#import?

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2008
Posts: 401
Reputation: CoolGamer48 is on a distinguished road 
Solved Threads: 40
CoolGamer48's Avatar
CoolGamer48 CoolGamer48 is offline Offline
Posting Pro in Training

#import?

 
0
  #1
Aug 10th, 2008
Hey,

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...".
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 401
Reputation: CoolGamer48 is on a distinguished road 
Solved Threads: 40
CoolGamer48's Avatar
CoolGamer48 CoolGamer48 is offline Offline
Posting Pro in Training

Re: #import?

 
0
  #2
Aug 10th, 2008
So #import is specific to Obj-C?
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: #import?

 
0
  #3
Aug 10th, 2008
It's a common practice in C++ to implement Object-C @import semantics via sacramental
  1. // Header file started...
  2. #ifndef HEADER_NAME_DERIVATIVE_ID
  3. #define HEADER_NAME_DERIVATIVE_ID
  4. // header contents here...
  5. #endif
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.
Last edited by ArkM; Aug 10th, 2008 at 4:50 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: #import?

 
0
  #4
Aug 10th, 2008
There are Obj_C #import analogues in some other languages (in PHP, for example), but no such directive in C and C++.
It's a common case, Object-C != C++...
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 351
Reputation: Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about 
Solved Threads: 62
Radical Edward's Avatar
Radical Edward Radical Edward is offline Offline
Posting Whiz

Re: #import?

 
1
  #5
Aug 10th, 2008
#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:
  1. #pragma once
  2.  
  3. // Header contents
That's roughly equivalent to this:
#ifndef magic name
#define magic name

// Header contents

#endif
The usual caveats apply: #pragmas aren't portable and #pragma once has a history of bugs on some compilers.
If at first you don't succeed, keep on sucking until you do succeed.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 747 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC