I'm starting upgrading my C knowledge from C99 to C11, and I wonder if my compiler is capable by default to understand C11 or I need the -std=c11
flag; how can I test it with a simple c11 source code not compiling with -std=c99
flag? There is also the C++11 standard, but I am starting from this article which is only about C.
I tried with some simple code using auto
declaration, but since it is a valid keyword also in C99 I'm a bit lost and asking here.
After publishing this question I received answers regarding the macro __STDC__VERSION__
, and also tried the code of this answer.
Surprisingly, the outputs of my tests were:
compile line: gcc main.c -std=c11 -o main.exe
oputput of main.exe: c11
compile line: gcc main.c -std=c99 -o main.exe
oputput of main.exe: c99
compile line: gcc main.c -o main.exe
oputput of main.exe: gnu90
The situation is that I can get the compiler capabilities at runtime, but still no at compile time.
For C++ I was able to find this sample code that does compile only with C++11:
int main()
{
int *p = nullptr;
}
As the nullptr is only available within C++11.