如何在#if处触发有关未定义符号的C预处理器错误? (LLVM / CLang / Xcode) [英] How to trigger C-preprocessor error about undefined symbol at #if? (LLVM/CLang/Xcode)

查看:79
本文介绍了如何在#if处触发有关未定义符号的C预处理器错误? (LLVM / CLang / Xcode)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何触发有关#if缺少定义的C预处理程序错误?
我正在使用LLVM / Clang / Xcode。

How to trigger C-preprocessor error about missing definition at #if? I'm using LLVM/Clang/Xcode.

此代码有效。

#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?

推荐答案

如果您想让编译器为您检查此操作,而无需重写您的代码,则可以按照-Wundef 开关nofollow>在此

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

在您的Xcode项目的TARGETS / YourTarget / Build Settings下,添加 -Wundef 到其他警告标志(又名 WARNING_CFLAGS )。

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

这篇关于如何在#if处触发有关未定义符号的C预处理器错误? (LLVM / CLang / Xcode)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆