I was wondering if there were any files in which I could set the -std=c99
flag, so that I would not have to set it for every compilation. I am using GCC 4.4 on Ubuntu.
Asked
Active
Viewed 1.7e+01k times
73
3 Answers
113
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.

Thomas Pornin
- 72,986
- 14
- 147
- 189
-
Ok I am new to programming on linux (learning at college), how do I use /usr/bin/c99 ? I am using Vim-Gnome with C plugin in which I just do \rr to compile and run. – Fatmarik Feb 03 '10 at 18:24
-
2From what I find on the Web, there is a global variable called `C_CCompiler` which designates the C compiler. It is normally set to `gcc`. Replace its contents with `c99` and things should go fine. See the help file on: http://lug.fh-swf.de/vim/vim-doc/csupport.html – Thomas Pornin Feb 03 '10 at 19:00
-
1Note that using c99 on Mac may give you surprising results: http://stackoverflow.com/questions/4182413 – dubiousjim May 31 '12 at 22:09
18
How about alias gcc99= gcc -std=c99
?

dirkgently
- 108,024
- 16
- 131
- 187
-
5+1 That's what I do. And while you are at it add the -Wall and -pedantic flags to the alias. – Feb 03 '10 at 17:03
-
5+1. Now that's what my alias actually looks like: `alias gcc99=gcc -Wall -pedantic -ansi -std=c99`. Yes, with `ansi` as well. – dirkgently Feb 03 '10 at 17:37
-
5@dirkgently: so what standard (if any) is GCC implementing with `-std=c99 -ansi`? You've enabled C99, and then disabled anything not in C89, does that result in the common subset of both? – Steve Jessop Feb 03 '10 at 18:45
-
1@Steve Jessop: GCC manual -- `This turns off certain features of GCC that are incompatible with ISO C90(when compiling C code), or of standard C++ (when compiling C++ code), such as the asm and typeof keywords, and predefined macros such as unix and vax that identify the type of system you are using. It also enables the undesirable and rarely used ISO trigraph feature. For the C compiler, it disables recognition of C++ style `//' comments as well as the inline keyword. ` Reading that section may be helpful: http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options – dirkgently Feb 03 '10 at 19:01
-
2I did read that, but it tells me what GCC does, not why it's useful ;-). In particular, how and why is `-ansi -std=c99 -pedantic` better than `-std=c89 -pedantic`? – Steve Jessop Feb 03 '10 at 19:20
-
1@Steve Jessop: Maximize portability, minimize vendor implementations. Also, don't much like `alloca` kind of functions. So on ... – dirkgently Feb 03 '10 at 19:21
-
Ah, no, I see what I misunderstood now. The -std=c99 overrides the -std=c89, because it occurs after it in the arguments. Or maybe only mostly overrides it. Is alloca disabled by `-ansi -std=c99`, but not by `-std=c99` alone? – Steve Jessop Feb 03 '10 at 19:25
-
@Steve Jessop: The order of arguments _does not_ matter. The combination does. – dirkgently Feb 03 '10 at 19:27
-
4The order certainly does matter. For example `int main() { // thing
}`, where – Steve Jessop Feb 03 '10 at 19:29is a newline. Compiles with `gcc -ansi -std=c99 -pedantic`, but not with `gcc -std=c99 -ansi -pedantic`. -
1Sorry, yes the order matters when they are of the same type. I stand corrected. http://gcc.gnu.org/onlinedocs/gcc/Invoking-GCC.html para#6 – dirkgently Feb 03 '10 at 19:44
-
1I'd add `-Wmissing-prototypes` and `-Wstrict-prototypes` (and maybe `-Wextra`). If I am confident the code will support it, I'd use `-Werror` too, for good measure; that treats any warnings as fatal errors. It is great discipline; it can be harsh, too. – Jonathan Leffler Feb 04 '10 at 07:07
1
export CFLAGS="-std=c99"
export CC="gcc"
make
Some distributions and in most UNIX based OS's have aliases or wrappers for this stuff.

lswiski
- 11
- 2