Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Compiler C++ Version Defaults

C++ -std=... default of various commonly used C++ compilers

Compiler Version __cplusplus
g++ 4.7.4 199711L
5.5.0 199711L
6.1.0 201402L
10.2 201402L
11.1.0 201703L
clang++ 3.4.2 199711L
5.0.0 199711L
6.0.0 201402L
12.0.1 201402L
hipcc 4.0.0 201103L
4.1.0 201103L
icpc 15.0.2 199711L
17.0.2 199711L
18.0.1 201402L
21.1.1 201402L
icpc (classic/oneAPI) 2021.1 Beta 20200602 201402L
icpx (oneAPI) 2021.1.2 201402L
dpcpp 2021.1-beta07 (2020.5.0.0604) 201703L
pgc++ 16.1 199711L
17.5 199711L
18.3 201402L
xlc++ 14.1b2 199711L
(XLClang) 16.1.1 199711L
crayc++ (classic) 8.7.9 201402L
crayc++ (LLVM) 9.0.0 201402L
msvc 19.28 199711L
19.28 199711L

Note: MSVC __cplusplus defines are unreliable.
Note: For Clang++, the -x hip|cuda frontend default differs from -x c++ for older releases.

Meaning of __cplusplus

__cplusplus C++ Standard
199711L C++98
201103L C++11
201402L C++14
201703L C++17
202002L C++20
TBD C++23

Meaning of __STDC_VERSION__

Random fun fact: The C standard for C-compilers defines a similar macro, __STDC_VERSION__:

__STDC_VERSION__ C Standard
undefined earlier
199409L C95
199901L C99
201112L C11
201710L C18

Default of various commonly used C compilers

Compiler Version __STDC_VERSION__
gcc 4.9.4 undefined
5.1.0 201112L
8.1 201710L
clang 3.0.0 199901L
3.5.2 199901L
3.6 201112L
11.0 201710L
icc (classic/oneAPI) 21.1.9 201112L
icpx (oneAPI) 2021.1.2 201710L


Inspired by

$CXX -dM -E -x c++  /dev/null | grep -F __cplusplus

or just check if this C++14 snippet compiles and read its assembly:

struct X {
    static constexpr int value = __cplusplus;

int main() {
    auto const x = X::value;
    return 0;

Equivalently for C:

cc -dM -E -x c  /dev/null | grep -F __STDC_VERSION__

or in code:

#include <stdio.h>

int main(){
    printf("%ld", __STDC_VERSION__);

This comment has been minimized.

Copy link

@ArmenGishyan ArmenGishyan commented Jan 10, 2020

Great job.


This comment has been minimized.

Copy link
Owner Author

@ax3l ax3l commented Jan 11, 2020

Thank you, I am glad it's helpful for you!


This comment has been minimized.

Copy link

@andreyv andreyv commented Oct 27, 2020

Note: __STDC_VERSION__ is also defined for C95 and C99.


This comment has been minimized.

Copy link
Owner Author

@ax3l ax3l commented Jan 6, 2021

Thank you, updated accordingly.
It's known but not all compilers define it prior to C11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment