How enable c99 mode in gcc with terminal

删除回忆录丶 提交于 2021-02-06 10:14:46

问题


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.


回答1:


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.




回答2:


You may try to use the -std=c99 flag.

Try to complile like this:

gcc -Wall -std=c99 -g myProgram.c

Also note that -g is for debugging option(Thanks Alter Mann for pointing that).




回答3:


Based on the comments under another answer, perhaps you are using the implicit make rules and don't have a Makefile. If this, then you are just runing make tst to generate tst binary from tst.c. In that case you can specify the flags by setting the environment variable CFLAGS. You can set it for the current shell, or add it to your ~/.bashrc to have it always, with this:

export CFLAGS='-Wall -Wextra -std=c99'

Or specifying it just for the single command:

CFLAGS='-Wall -Wextra -std=c99' make tst

(Note: I added warning flags too, you should really use them, they will detect a lot of potential bugs or just bad code you should write differently.)



来源:https://stackoverflow.com/questions/25566597/how-enable-c99-mode-in-gcc-with-terminal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!