How are the __cplusplus directive defined in various compilers?

The 199711L stands for Year=1997, Month = 11 (i.e., November of 1997) -- the date when the committee approved the standard that the rest of the ISO approved in early 1998.

For the 2003 standard, there were few enough changes that the committee (apparently) decided to leave that value unchanged.

For the 2011 standard, it's required to be defined as 201103L, (again, year=2011, month = 03) again meaning that the committee approved the standard as finalized in March of 2011.

For the 2014 standard, it's required to be defined as 201402L, interpreted the same way as above (February 2014).

For the 2017 standard, it's required to be defined as 201703L (March 2017).

For the 2020 standard, the value has been updated to 202002L (February 2020).

Before the original standard was approved, quite a few compilers normally defined it to 0 (or just an empty definition like #define __cplusplus) to signify "not-conforming". When asked for their strictest conformance, many defined it to 1.

I almost forgot to mention, but one more tidbit about ancient compilers: a few of the earliest versions of cfront (and probably a few others copying it) defined c_plusplus instead of __cplusplus. I don't recall it's being defined to any meaningful value though.


I think preprocessor defines for the various versions should go into SD-6:

#define __cpp_1997 199711L
#define __cpp_2003 __cpp_1997
#define __cpp_2011 201103L
#define __cpp_2014 201402L
#define __cpp_2017 201703L

Looking into the 2020s we might have three more standards. I don't doubt that many implementors will have code supporting standards from 1997 onwards.

I for one would like a mnemonic define so I won't have to keep coming back to this post.


That means it is compatible with the 1997 C++ standard (actually known as C++ '98 as they took too long to ratify it..


__cplusplus value for C++20

According to Acorn's answer __cplusplus is macro defined as 202002 based on the link cpp.predefined(1.1)! This definition is also to be found at this cppreference! Search for __cplusplus

This has since been updated to 202004

To know its actual value for Microsoft Visual C++ in Visual Studio community 2019 do the following:

  • Create a Visual C++ project
  • Right mouse click on the Solution.
  • On the dropdown menu click on Properties at the bottom
  • A pop up dialog opens up
  • Click on "Configuration Properties" to expand it
    • Click on "C/C++" to expand it.
      • Click on "All Options".
        • You should find "Additional Options" on the right
          • On the adjacent right column of this paste: /std:c++latest /Zc:__cplusplus

Click "Apply" button and then the "OK" button

In function main() run the following code to get the value of __cplusplus

int main()
{
    long cppVer = __cplusplus;
    std::cout << "__cplusplus value for C++20 is: ";
    std::cout << std::to_string( cppVer ) << std::endl;
}

The code should display the following:

__cplusplus value for C++20 is: 202004