开发者

How to trigger C-preprocessor error about undefined symbol at #if? (LLVM/CLang/Xcode)

开发者 https://www.devze.com 2023-01-18 09:42 出处:网络
How to trigger C-preprocessor error about missing definition at #if? I\'m using LLVM/Cl开发者_StackOverflow社区ang/Xcode.

How to trigger C-preprocessor error about missing definition at #if? I'm using LLVM/Cl开发者_StackOverflow社区ang/Xcode.

This code works.

#define AAAAA 1
#if AAAAA
#endif

And I expected this code will be an error for undefined symbol.

//#define AAAAA 1     Removed definition.
#if AAAAA
#endif

But it did not. Is this standard/regular behavior? And is there other way to triggering preprocessor error?


It sounds like you want to raise an error if a particular symbol is not defined. If so then just use the #error preprocessor directive

#ifndef AAAAA
#error Some Message
#endif


If you want to let the compiler check this for you, without rewriting your code, you can use the -Wundef switch as documented here.

In your Xcode project under TARGETS / YourTarget / Build Settings, add -Wundef to "Other Warning Flags" (aka. WARNING_CFLAGS).

0

精彩评论

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

关注公众号