40

I currently use gcc 4.6.3. My understanding is that gcc by default uses the gnu89 standard and I would like to enable C11, the latest C standard. I tried:

[pauldb@pauldb-laptop test ]$ gcc -std=c11 -o test test.c
cc1: error: unrecognised command line option ‘-std=c11’

I replaced c11 with gnu11 and I get the same error. What is the correct way to enable the latest C standard for gcc?

(Note: I'm interested in the latest C standard and not the latest C++ one.)

Paul Baltescu
  • 1,765
  • 4
  • 21
  • 28
  • If you are interested in a working wrapper around gcc that impements many interesting bits of C11 have a look into P99, p99.gforge.inria.fr – Jens Gustedt Apr 27 '13 at 21:47

4 Answers4

59

The correct option is -std=c11.

However, it is not available in gcc 4.6. You need at least gcc 4.7 to have this option supported. In some older versions like gcc 4.6, the option -std=c1x was available with experimental (i.e., very limited) support of C11.

Note that the current version of gcc is gcc 8.2.

MultiplyByZer0
  • 4,341
  • 3
  • 27
  • 46
ouah
  • 134,166
  • 14
  • 247
  • 314
  • 1
    correct answer, but to my experience the `-std=c11` is not working yet, be carefull. There are some pieces of C11 missing in gcc, so it is not (yet) easy to work with C11 and gcc. – Jens Gustedt Apr 27 '13 at 21:45
  • 1
    4.8.1 has just been released http://gcc.gnu.org/ml/gcc-announce/2013/msg00004.html with fully support – bluszcz Jun 04 '13 at 08:14
  • 3
    @bluszcz That's talking about g++ and C++11, does the same go for gcc and C11? – complistic Jun 05 '13 at 03:50
3

Just to let you know GCC 4.9.x has far more complete support than older versions. If you really need to use this feature, please switch to anything 4.8+ Here is the support status -- https://gcc.gnu.org/wiki/C11Status

KeshV
  • 616
  • 6
  • 8
3

gcc 5.2.0 works with command line option ‘-std=c11’

Janos
  • 31
  • 1
1

Inside a .spec file :

%define gcc_ver %(if [[ $(gcc -dumpversion) > 4.7 ]]; then echo 1; else echo 0; fi)
# Do we use c11 ?
%if 0%{?gcc_ver} < 1
  %global std_c11 0
%else
  %global std_c11 1
%endif

# if the configure of the package supports it add :
%if %{std_c11}
  --enable-cxx11 \
%endif
rmstock
  • 21
  • 1
  • 5
    While this code may answer the question, providing additional context regarding _why_ and/or _how_ it answers the question would significantly improve its long-term value. Please [edit] your answer to add some explanation. – Toby Speight Apr 06 '16 at 17:50