I want to know which C standard I am currently using in my Visual Studio C++, but I have a trouble using the __STDC_VERSION__
predefined macro and other C99 predefined macros - an error indicating that this identifier is not defined appears and when I used #ifndef __STDC_VERSION__
it seems that it is not defined. Does this mean that I am using ANSI C?
Below is a sample code for using __STDC_VERSION__
:
int main(void) {
printf("%d\n", __STDC_VERSION__);
return 0;
}
The only C standard that Visual C++ supports fully is the ANSI-89/ISO-90 first standard. There is no official support for C99 or C11; but there is enough of C99 supported to make C++11 and C++14 work.
What I use for source code portability is #ifdef _MSC_VER
and expect only C89/C90 support if that's defined. (If you need finer detail, you can test the value of _MSC_VER to see which version. There's a list of MSC/C++ versions and their _MSC_VER values at Wikipedia.
Obviously, that has to be tested before any of the C99 or C11 macros. As a special note, if a Microsoft compiler defines __STDC__
then you don't get even partial support for C99. That macro is only defined when compiling with the /Za
option, which disables any Microsoft extensions--including C++/C99 bits like //
comments, mixed declarations and code in a block, or declarations in for
statements.