Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How enable c99 mode in gcc with terminal

Tags:

c

gcc

c99

I want to activate c99 mode in gcc compiler to i read in other post in this forum that -std should be equal to -std=c99 but i don't know how to set it to this value using command line so please help.

like image 232
user297904 Avatar asked Aug 29 '14 10:08

user297904


People also ask

Does GCC use C99?

C99 is substantially completely supported as of GCC 4.5 (with -std=c99 -pedantic-errors used; -fextended-identifiers also needed to enable extended identifiers before GCC 5), modulo bugs and floating-point issues (mainly but not entirely relating to optional C99 features from Annexes F and G).

How do I use C11 in GCC?

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.

How do you use std C99 flag?

Instead of calling /usr/bin/gcc , use /usr/bin/c99 . This is the Single-Unix-approved way of invoking a C99 compiler. On an Ubuntu system, this points to a script which invokes gcc after having added the -std=c99 flag, which is precisely what you want.


1 Answers

Compile using:

gcc -std=c99 -o outputfile sourcefile.c

gcc --help lists some options, for a full list of options refer to the manual. The different options for C dialect can be found here.

As you are using make you can set the command line options for gcc using CFLAGS:

# sample makefile
CC = gcc
CFLAGS = -Wall -std=c99
OUTFILE = outputfile
OBJS = source.o
SRCS = source.c

$(OUTFILE): $(OBJS)
        $(CC) $(CFLAGS) -o $(OUTFILE) $(OBJS)
$(OBJS): $(SRCS)
        $(CC) $(CFLAGS) -c $(SRCS)

Addendum (added late 2016): C99 is getting kind of old by now, people looking at this answer might want to explore C11 instead.

like image 160
jpw Avatar answered Sep 16 '22 22:09

jpw