Can __cplusplus be defined and equal to zero?

The question is whether to wrap extern "C" with #if or #ifdef . i.e:.

 #if __cplusplus extern "C" { #endif 

or

 #ifdef __cplusplus extern "C" { #endif 

What begs the question: is there ever a situation where __cplusplus is determined to be zero?

+5
source share
1 answer

In accordance with the standard, the __cplusplus macro must be defined, the exact definition depends on the C ++ standard used, but it will not be zero.

For example, for C ++ 11 it should be 201103L , with the note "It is assumed that future versions of this standard will replace the value of this macro with a larger value."

Historically, in some ancient non-compliant compilers that you could possibly dig, __cplusplus was defined as 0 to indicate non-compliance with the standard. This is of historical interest only.

See: How is the __cplusplus directive defined in different compilers?

+3
source

Source: https://habr.com/ru/post/1271705/


All Articles