/compat/c/gcc-std-values-for-c
gcc -std values for C: c89, c99, c11, c17, c23 and gnu17 mapped to __STDC_VERSION__
- tool
- C
- versions
- C90, C99, C11, C17, C23
- os
- any
gcc -std=VALUE selects the C standard: c99, c11, c17 and c23 accept the ISO standard of that year, and gnu99, gnu11, gnu17 and gnu23 add GNU extensions on top. The value also decides __STDC_VERSION__, the macro your code can test. The tables follow the GCC manual on C dialect options and standard predefined macros.
Values
| Standard | -std values | __STDC_VERSION__ |
|---|---|---|
| C90 (ISO C 1990) | c90, c89, iso9899:1990 (same as -ansi) | not defined by plain C90 |
| C90 with amendment 1 | iso9899:199409 | 199409L |
| C99 | c99, iso9899:1999 | 199901L |
| C11 | c11, iso9899:2011 | 201112L |
| C17 | c17, iso9899:2017, iso9899:2018 | 201710L |
| C23 | c23, iso9899:2024; c2x is deprecated | 202311L |
The GNU dialects are gnu90, gnu99, gnu11, gnu17 and gnu23. The old names c9x, iso9899:199x and gnu9x are deprecated spellings of C99. C17 is C11 with defect corrections and a new version number, so it is supported as well as C11 is.
What the default is
The default depends on the GCC release. The manual describes gnu23 as the default for C code; older releases default to a GNU dialect of C17. Do not rely on either: put -std= in your build.
Check your compiler
for std in c99 c11 c17 gnu17; do
printf '%s: ' "$std"
echo '__STDC_VERSION__' | gcc -std=$std -x c -E -P - | tail -n 1
done
echo '__STDC_VERSION__' | gcc -x c -E -P - | tail -n 1Output
c99: 199901L c11: 201112L c17: 201710L gnu17: 201710L 201710L
The last line is the version of the default dialect of the installed compiler.
Choosing a value
- Portable library:
-std=c11or-std=c99with-pedanticwarns about anything outside the standard. - Linux application using GNU or POSIX features: the
gnudialect, so functions such asstrdupare declared without extra macros. A missing declaration shows up as implicit declaration of function. - New language features (see C17 to C23):
-std=c23, on a compiler that knows the name.
C++ has the same idea with another macro, see __cplusplus values. For compile commands see compile and run a C program.
FAQ
What is the default C standard in gcc?
It depends on the GCC release. The current GCC manual says gnu23 is the default for C code, while older releases default to gnu17. Print __STDC_VERSION__ with your own compiler to be sure, and pass -std explicitly in build scripts.
What is the difference between -std=c11 and -std=gnu11?
-std=c11 accepts programs that follow ISO C11 and disables GNU extensions that conflict with it. -std=gnu11 is the GNU dialect of C11 and keeps those extensions. Both set the same __STDC_VERSION__ value.
Why does gcc reject -std=c23?
Older GCC releases do not know the name c23 and fail with unrecognized command-line option. They accept the deprecated name c2x for the draft instead. Upgrade the compiler, or use -std=c2x on the old one.