I read here it is C90 with extensions. How can I know for sure?
Use the -std=
flag to specify a language dialect: c89
, c99
, c++98
, etc. Note that c90
is equivalent to c89
.
As a shorthand -ansi
causes -std=c89
in C mode and -std=c++98
in C++ mode.
Use -pedantic
to enable all diagnostics that the standards require.
The defaults are gnu89
for C and gnu++98
for C++. Consult the manual for detailed descriptions of the various dialects.
Update:
For gcc version greater than 5.0, defualt is gnu11
-std=c11
. See my answer. –
Tamarin Try below command and search for std
gcc -v --help | less
It will show you all the available options for your gcc.
gcc -v --help 2> /dev/null | grep 'Conform.*C standard'
–
Schlep Read the manpage. On my computer (OSX 10.7, gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)):
-std=
Determine the language standard. This option is currently only supported
when compiling C or C++.A value for this option must be provided; possible values are
....
gnu89
Default, ISO C90 plus GNU extensions (including some C99 features).....
gnu++98
The same as -std=c++98 plus GNU extensions. This is the default for C++ code.
man gcc
says that there isn't a man page for gcc. Wat? –
Spoil Use the -std=
flag to specify a language dialect: c89
, c99
, c++98
, etc. Note that c90
is equivalent to c89
.
As a shorthand -ansi
causes -std=c89
in C mode and -std=c++98
in C++ mode.
Use -pedantic
to enable all diagnostics that the standards require.
The defaults are gnu89
for C and gnu++98
for C++. Consult the manual for detailed descriptions of the various dialects.
Update:
For gcc version greater than 5.0, defualt is gnu11
-std=c11
. See my answer. –
Tamarin No version of gcc fully conforms to any ANSI or ISO C standard by default. The default is always equivalent to -std=gnuNN
, supporting the given standard with GNU-specific extensions. Prior to version 5 (and going back a number of years), the default was -std=gnu90
. Starting with version 5, the default is -std=gnu11
.
There have been three ISO C standards: C90, C99, and C11. (C95 was a minor amendment to C90.) The first ANSI C standard was published in 1989, and is known as C89; it describes the same language as the ISO C90 standard.
To find out the default language version for the gcc you have running, type
info gcc
search for the phrase "The default".
This assumes that you have the gcc documentation installed, that the documentation shown by info gcc
matches the version of gcc you're running, and that the wording is similar enough that searching for "The default" will find the correct information. None of these is guaranteed. Older gcc manuals may be organized differently.
More reliably, run
gcc --version
to see what version you're running, then visit the GCC online documentation page and read the documentation for the version you're running.
More simply, if you have a version before 5.0, the default is -std=gnu89
; otherwise the default is -std=gnu11
. (That may change in a future release, but only some time after a new ISO C standard is published and the gcc maintainers have had time to implement it and decide to make it the default. Don't hold your breath.)
Or you can avoid the question altogether by specifying the version you want using the -std=...
command-line option.
You can also check one of the predefined Macros, for example whether your GCC asks for ANSI C (STRICT__ANSI) by default (i.e. without any cli arguments).
You can use the value of the __STDC_VERSION__
macro found with
echo | gcc -D -dM - | grep STDC
Use STDC
and not the full __STDC_VERSION__
because __STDC_VERSION__
would not be defined under C90.
Note that this will not tell you if GNU extensions are supported or not. They are normally enabled and would require specific gcc
options such as -std=c17 -pedantic -pedantic-errors
to disable. Full explanation of GCC's behavior with respect to how command-line arguments affect the application of standards during compilation is well beyond the scope of this answer.
(Yes, there is another, older, answer that alludes to this with a link-only answer. This answer is meant to provide an actual example of how to extract the information along with supporting quotes from standards documents.)
Supporting Documentation
Per (draft) C11 6.10.8.1 Mandatory macros, paragraph 1:
The following macro names shall be defined by the implementation:
...
__STDC_VERSION__ The integer constant 201ymmL.
Footnote 178 further explains
This macro was not specified in ISO/IEC 9899:1990 and was specified as 199409L in ISO/IEC 9899/AMD1:1995 and as 199901L in ISO/IEC 9899:1999. The intention is that this will remain an integer constant of type long int that is increased with each revision of this International Standard.
The draft C 23, err, 24 standard(warning: PDF!) has this:
6.10.9.1 Mandatory macros
1 The following macro names shall be defined by the implementation:
...
__STDC_VERSION__
The integer constant 202311L.
with footnote 227 adding that the history of __STDC_VERSION__
can be found in Annex M of the standard:
See Annex M for the values in previous revisions. The intention is that this will remain an integer constant of type
long int
that is increased with each revision of this document.
The earliest documented version is
...
M.6 First Edition, Amendment 1
Major changes in the amendment to the first edition (
__STDC_VERSION__ 199409L
) included...
© 2022 - 2025 — McMap. All rights reserved.