Moe*_*oeb 21 c c++ c-preprocessor
我从#猜测它只是一个编译时实用工具.如何在C/C++程序中使用它?
在互联网上找不到太多.任何链接都会有所帮助.
Jam*_*lis 18
它会导致编译器(或预处理器)输出错误消息.在C++中,它还使翻译单元格式不正确(即,它导致编译失败).
如果您有几个可以定义的宏,并且您希望确保只定义了它们的某些组合,则可以使用这些#error来在编译无效组合时导致编译失败.
如果你想确保从不编译某些代码块(无论出于何种原因),它也会很有用.
Han*_*ant 11
用于检查编译器设置以及验证宏值组合.一些随机的例子:
#if !defined(_DLL)
# error This code will only work properly when compiled with /MD
#endif
#if _WIN32_WINNT < 0x502
# error Sorry, Windows versions prior to XP SP2 are not supported
#endif
#if defined(_APPLE) && defined(_LINUX)
# error Conflicting operating system option selected, choose one.
#endif
Run Code Online (Sandbox Code Playgroud)