tags:

views:

394

answers:

3

What gcc options shall I use to enforce ANSI C (C99) warnings/errors? gcc (GCC) 3.4.2 (mingw-special)

I'm using: gcc -pedantic -ansi -std=c99 is this correct?

+1  A: 
-ansi
    In C mode, this is equivalent to -std=c89. In C++ mode, it is equivalent to -std=c++98.

ANSI C isn't the same as C99 (yet). Also, -Wall might also be of interest, but only -pedantic should do what you want.

Mikael S
"ANSI C isn't the same as C99". ANSI has adopted C99 as a standard. It's just that for whatever reason, C89 came to be called "ANSI C", to distinguish it from pre-standard C, and the name has stuck around.
Steve Jessop
+7  A: 

The -ansi flag is synonymous with the -std=c89 flag.

Just using -std=c99 with -pedantic should be sufficient.

When in doubt, you can always refer to the documentation.

James McNellis
+1  A: 

This is an old question but I just wanted to add some extra points.

Firstly, regardless of the set of generic command-line switches you supply to GCC, currently it doesn't appear to be possible to make GCC to report all constraint violations as "errors" and everything else as "warnings". Some of the diagnostic messages GCC reports as "warnings" are in fact constraint violations (i.e. "errors") from the point of view of C language, but there's no way to force GCC to recognize that fact and generate an "error" diagnostic. Quite possibly that a more precise separation can be achieved by fine-tuning individual warning types, but I'm not sure GCC settings provide sufficient granularity to achieve a good match.

Secondly, GCC provides -pedantic-errors option that can be used in place of plain -pedantic, which is intended to enable a more precise (as described above) classification of diagnostic messages into "errors" and "warnings". It is still far from perfect though.

P.S. The language specification doesn't require/define the separation of diagnostic messages into "errors" and "warnings", but in practice many programmers expect constraint violations to be reported as "errors". I thought that you might have meant something like that when you mentioned "enforcing warnings/errors" in your question.

AndreyT