我正在查看 BSON 源代码,发现了一些我以前从未见过的东西。
#if !defined(BSON_INSIDE) && !defined(BSON_COMPILATION)
#error "Only <bson.h> can be included directly."
#endif
上面的define(XXXX)
宏是什么?我可以猜测它的作用,但我似乎找不到任何有关它的文档。它特定于某些编译器吗?它向我发出了有关 Microsoft Visual C++ 的 W4 警告(我正在尝试在项目中解决该警告)。
最佳答案
来自6.10.1
The expression that controls conditional inclusion shall be an integer constant expression except that: identifiers (including those lexically identical to keywords) are interpreted as described below;166) and it may contain unary operator expressions of the form
defined identifier
or
defined ( identifier )
which evaluate to 1 if the identifier is currently defined as a macro name (that is, if it is predefined or if it has been the subject of a
#define
preprocessing directive without an intervening#undef
directive with the same subject identifier), 0 if it is not.
它不是宏
- 它是一个运算符。
关于c++ - C/C++ 中定义的(XXXX) 宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48200410/