How to check which version of C my compiler is using?
To check against standard versions, use __STDC__
and __STDC_VERSION__
. Various compilers also offer implementation specific macros for further refinement.
__STDC__
available with C89 version and onward.
Compliant versions prior to C94 do not certainly define __STDC_VERSION__
. Since then it is a long
constant.
The common values found include:
199409L
199901L
201112L
201710L
Putting that together
#if defined(__STDC__)
#if defined(__STDC_VERSION__)
printf("Version %ld\n", __STDC_VERSION__);
#else
puts("Standard C - certainly 1989");
#endif
#else
puts("Pre 1989 or non-compliant C");
#endif
Example macro usage