The question came up of whether one should wrap extern "C"
using #if
or #ifdef
. i.e.:
#if __cplusplus
extern "C" {
#endif
or
#ifdef __cplusplus
extern "C" {
#endif
Which begs the question: is there ever a situation where __cplusplus is defined to be equal to zero?
According to the standard, the __cplusplus
macro must be defined, the exact definition depends on the C++ standard being used but it will not be zero.
For example, for C++11 it must be 201103L
, with the note "It is intended that future versions of this standard will replace the value of this macro with a greater value."
Historically, in some ancient non-conforming compilers you could probably dig up, __cplusplus
was defined to 0 to indicate non-conformance with the standard. This is only of historical interest.
See: How are the __cplusplus directive defined in various compilers?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With