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

佐手、 提交于 2020-01-03 21:48:23

问题


How to trigger C-preprocessor error about missing definition at #if? I'm using LLVM/Clang/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?


回答1:


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).




回答2:


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


来源:https://stackoverflow.com/questions/3852507/how-to-trigger-c-preprocessor-error-about-undefined-symbol-at-if-llvm-clang-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!