| | |
#import?
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Hey,
I'm learning Objective-C, and they use
I'm learning Objective-C, and they use
#import "File.h" instead of #include "File.h" . The tutorial I'm using says that import is like an include once thing, and it basically implements the #ifndef blocks that's normally done manually in C++. I was just wondering if this is something specific to Objective C, or if it's built into the C predecessor, and technically could be used with C++, but just isn't commonly. I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
It's a common practice in C++ to implement Object-C @import semantics via sacramental
No special standard features in C++ and C preprocessors to do it.
The #import preprocessor directive in MS Visual C++ has totally different semantics (strictly speaking, it's not preprocessor directive at all). There are another directives (for example, #pragma once) but they are not standard (portable) ones too.
C++ Syntax (Toggle Plain Text)
// Header file started... #ifndef HEADER_NAME_DERIVATIVE_ID #define HEADER_NAME_DERIVATIVE_ID // header contents here... #endif
The #import preprocessor directive in MS Visual C++ has totally different semantics (strictly speaking, it's not preprocessor directive at all). There are another directives (for example, #pragma once) but they are not standard (portable) ones too.
Last edited by ArkM; Aug 10th, 2008 at 4:50 pm.
#import isn't available in C or C++, but if you want the same effect of it, some compilers implement a special #pragma for header files called once:
That's roughly equivalent to this:
The usual caveats apply: #pragmas aren't portable and
C++ Syntax (Toggle Plain Text)
#pragma once // Header contents
#ifndef magic name #define magic name // Header contents #endif
#pragma once has a history of bugs on some compilers. If at first you don't succeed, keep on sucking until you do succeed.
![]() |
Similar Threads
- Import excel records into ASP database (ASP)
- vbulletin import problem (Existing Scripts)
- I Want To Import A Database Tables Into Treeview (VB.NET)
- Import/export tab delimited file (PHP)
- how to burn dvd directly from firewire import (OS X)
- How do import a worksheet to HTML? (HTML and CSS)
- can't import mp3 CD''s to iTunes...WHY??? (OS X)
Other Threads in the C++ Forum
- Previous Thread: namespace std
- Next Thread: Is this good programming practice? or is it problematic?
Views: 747 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






