Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable c11 on later versions of gcc?

Tags:

c

gcc

c11

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.)

like image 567
Paul Baltescu Avatar asked Apr 27 '13 20:04

Paul Baltescu


People also ask

How do I enable C11 in GCC?

The correct option is -std=c11 .

Does GCC support C++11?

GCC provides experimental support for the 2011 ISO C++ standard. This support can be enabled with the -std=c++11 or -std=gnu++11 compiler options; the former disables GNU extensions. As of GCC 4.8.

How do I enable C++11?

H2CO3 is right, you can use a makefile with the CXXFLAGS set with -std=c++11 A makefile is a simple text file with instructions about how to compile your program. Create a new file named Makefile (with a capital M). To automatically compile your code just type the make command in a terminal.

How do you specify STD C++11 in your Makefile?

You can use command-line flag -std to explicitly specify the C++ standard. For example, -std=c++98 , or -std=gnu++98 (C++98 with GNU extensions) -std=c++11 , or -std=gnu++11 (C++11 with GNU extensions)


2 Answers

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.

like image 88
ouah Avatar answered Sep 26 '22 22:09

ouah


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

like image 42
KeshV Avatar answered Sep 24 '22 22:09

KeshV