Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can __cplusplus ever be defined and equal to zero? [duplicate]

Tags:

c++

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?

like image 647
jpsamper Avatar asked Oct 18 '22 06:10

jpsamper


1 Answers

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?

like image 82
Dietrich Epp Avatar answered Oct 20 '22 05:10

Dietrich Epp