Reputation: 936
I write c
code and run it with gcc
. Well everything works. But I don't know which version I am using. Today in Wikipedia C (programming language) I saw that the latest stable release of this language is C17 / June 2018; 3 years ago
. So, I am curious to know my version. Is there any way to know this? I am using Ubuntu Linux.
EDIT: I want to know the c
version which used by the gcc
when i just use gcc programm.c
or gcc -o programm.out programm.c
. Actually which c
version is used by gcc
by default.
Upvotes: 0
Views: 4787
Reputation: 14107
You could use a predefined macro __STDC_VERSION__
link in your code. It expands to an long
integer in yyyymmL
format (i.e. 199901L
signifies C99).
For example:
#include <stdio.h>
int main() {
printf("%ld\n", __STDC_VERSION__);
return 0;
}
Compiled with gcc
9.3 with no flags print:
201710
While compiled with -std=c2x
option produces:
202000
Using a macro will let you handle different versions of C language directly in your code.
Upvotes: 2
Reputation: 399713
Assuming you meant "what version of the C language", then yes of course, you use the -std
command line option to specify.
The manual page has a lot to say, it begins:
-std=
Determine the l standard. This option is currently only supported when compiling C or C++.
The default, as mentioned by the man page, is gnu89
, so it's a good idea to change it, to compile C17 code you would do:
$ gcc -std=c17 -o my-new-program my-new-program.c
The default can change with a new release of GCC, which is another good reason to specify it yourself on the command line if you want to be sure.
If you just meant which compiler release you're using, then that's printed by the --version
option:
$ gcc --version
gcc (Ubuntu 10.2.0-13ubuntu1) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Fresh.
Upvotes: 1
Reputation: 133
If you are using gcc you can use the following commands to know the compiler version.
gcc --version
gcc -v
And then you can set std
to compile a particular version of C in your case c17.
gcc -std=c17 sample.c -o sample
Upvotes: 0