75

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.

3 Answers 3

117

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
From 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: lug.fh-swf.de/vim/vim-doc/csupport.html
Note that using c99 on Mac may give you surprising results: stackoverflow.com/questions/4182413
19

How about alias gcc99= gcc -std=c99?

11 Comments

+1 That's what I do. And while you are at it add the -Wall and -pedantic flags to the alias.
+1. Now that's what my alias actually looks like: alias gcc99=gcc -Wall -pedantic -ansi -std=c99. Yes, with ansi as well.
@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?
I 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?
The order certainly does matter. For example int main() { // thing <newline> }, where <newline> is a newline. Compiles with gcc -ansi -std=c99 -pedantic, but not with gcc -std=c99 -ansi -pedantic.
|
3
export CFLAGS="-std=c99"
export CC="gcc"

make 

Some distributions and in most UNIX based OS's have aliases or wrappers for this stuff.

1 Comment

This did it for me, thanks! The gcc call was deep inside nested pip installs, so it was difficult to find all of the places I'd need to change it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.