next up previous
Next: Automating the Process with Up: Compiling with GCC Previous: Common Command-line Options


Error Checking and Warnings

GCC boasts a whole class of error-checking, warning-generating, command-line options. These include -ansi, -pedantic, -pedantic- errors, and -Wall. To begin with, None of these options, however, guarantee that your code, when compiled without error using any or all of these options, is 100 percent ANSI/ISO-compliant.

Consider http://siber.cankaya.edu.tr/SystemsProgramming/cfiles/pedant.cpedant.c , an example of very bad programming form. It declares main() as returning void, when in fact main() returns int, and it uses the GNU extension long long to declare a 64-bit integer.

// pedant.c - use -ansi, -pedantic or -pedantic-errors
#include <stdio.h>
 void main(void)
{
        long long int i = 01;
        fprintf(stdout, "This is a non-conforming C program\n");
}
Using
%gcc pedant.c -o pedant
this code compiles without complaint. To reiterate, the -ansi, -pedantic, and -pedantic-errors compiler options do not insure ANSI/ISO-compliant code. They merely help you along the road.

Some users try to use -pedantic to check programs for strict ANSI C conformance.


next up previous
Next: Automating the Process with Up: Compiling with GCC Previous: Common Command-line Options
Cem Ozdogan 2007-02-19