开发者

Need help understanding preprocessor message macros in XCode

I haven't had a need to use preprocessor macros much before, and came across this bit of code on the web:

#ifndef LITE_VERSION 
    #ifndef FULL_VERSION
        #error
    #endif 
#endif

The goal of this is to warn if either LITE or FULL is not declared. I've dropped this in my Prefix.pch file and I receive a warning with the #error statement.

I tried changing the error to:

#pragma message("some text")

And while this will compile, no text is displayed (that I can see).

I've not declared the LITE or FULL yet, so I'm wondering why this 开发者_开发技巧doesn't work.


This should be:

#pragma message "some text"

Or you could use this if you prefer:

#pragma message ("some text")

See http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html

Typically I use a slightly different approach:

#if defined(LITE_VERSION)
   ...
#elseif defined(FULL_VERSION)
   ...
#else
#error "Must define LITE_VERSION or FULL_VERSION"
#end


It should work with the error as you had it before. Just add a message and build

#ifndef LITE_VERSION
    #ifndef FULL_VERSION
        #error "Neither Lite or Full version has been defined"
    #endif
#endif
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜