Question

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?

Was it helpful?

Solution

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 GCC documentation. As of GCC 3.4.2, the chapter to read is 2 - Language Standards Supported by GCC.

OTHER TIPS

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 not 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.

-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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top