I can't seem to find an answer to this question by Googling. Can I assume that the Objective-C preprocessor works exactly identically to the C preprocessor, and that anything I read about the C preprocessor applies exactly the same way in an Objective C environment? Or are there subtle differen开发者_开发问答ces?
The official documentation from Apple states that Obj-C is a small superset to the language. As far as I can tell, the preprocessor is the same as regular C's (It's all based on the same open-source components, anyway). That's true with the GCC compiler (which is used elsewhere) and related tools; I would assume LLVM is the same as well but I can't speak for the latter.
Of note would be #pragma
s, but then again they were meant to be implementation-dependent.
There are some subtle differences:
- The include paths are different depending on what language you are using.
- I believe that
#import
triggers a warning if you're not using ObjC. - The preprocessor may have some special cases to handle the ObjC
@"string"
syntax. - And, of course, most importantly, the language affects which macros are predefined (e.g,
__objc__
).
It's still cpp
either way, though -- it's just operating in a different mode.
It's the same preprocessor. You can look at the Clang or GCC source if you want to see for yourself — as far as I can tell, aside from the fact that it uses the Objective-C lexer rather than the C one, it's the same.
精彩评论