Skip to content

/compat/c/gcc-std-values-for-c

gcc -std values for C: c89, c99, c11, c17, c23 and gnu17 mapped to __STDC_VERSION__

verified onenvironmentlocal · linux 6.18.44-fc-v236 x64 · GNU bash 5.2.21updated
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 1iso9899:199409199409L
C99c99, iso9899:1999199901L
C11c11, iso9899:2011201112L
C17c17, iso9899:2017, iso9899:2018201710L
C23c23, iso9899:2024; c2x is deprecated202311L

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

bash
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 1

Output

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

  1. Portable library: -std=c11 or -std=c99 with -pedantic warns about anything outside the standard.
  2. Linux application using GNU or POSIX features: the gnu dialect, so functions such as strdup are declared without extra macros. A missing declaration shows up as implicit declaration of function.
  3. 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.

Sources