-1

I'm going through the BSON source code, and came across something I've never seen before.

Line 22 in bson-macros.h:

#if !defined(BSON_INSIDE) && !defined(BSON_COMPILATION)
#error "Only <bson.h> can be included directly."
#endif

What is the defined(XXXX) macro above? I can guess what it does, but I can't seem to find any documentation about it. Is it specific to some compilers? It gives me a W4 warning on Microsoft Visual C++ (that I'm trying to resolve in my project).

aaronsnoswell
  • 6,051
  • 5
  • 47
  • 69

1 Answers1

4

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

It is not macro - it is an operator.

user2736738
  • 30,591
  • 5
  • 42
  • 56
  • Wow. Thank you - I had no idea this existed. – aaronsnoswell Jan 11 '18 at 05:54
  • That's a C reference. Is it also valid for C++? – Jongware Jan 13 '18 at 02:20
  • 1
    @aaronsnoswell.: Again we see how tagging leads to these kind of situation. My answer was solely given for C - I am not aware whether the C++11 or C++14 standard alllows it or not...if I find anything useful(absence or presene ) will update. – user2736738 Jan 13 '18 at 02:55