c++ - C/C++ 中定义的(XXXX) 宏?

标签 c++ c operators defined

我正在查看 BSON 源代码,发现了一些我以前从未见过的东西。

Line 22 in bson-macros.h :

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

相关文章:

c - 如何从内存中读取16位值

c - 将 stdint.h 包含在头文件中会破坏使用 Clock_gettime() 进行的编译

C++串口库对Win32同步函数的使用?

c - 使用 b^n 次方求矩阵的逆

c++ - 访问未初始化的值会导致性能下降吗?

javascript - "undefined"变量与 Javascript 中的空格的字符串连接

linux - bash 命令 XOR ^ 另一个命令

scala - Scala- boolean 值-&vs &&,| vs ||

c++ - 如何在树访问者中进行每个节点缓存

c++ - 为什么在 visual studio 2013/2015 上出现 vsnprintf 崩溃?