Writing reliable numerical programs in C requires great care. The following GCC warning options are recommended when compiling numerical programs:
gcc -ansi -pedantic -Werror -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wtraditional -Wconversion -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wnested-externs -fshort-enums -fno-common -Dinline= -g -O4
For details of each option consult the manual Using and Porting GCC. The following table gives a brief explanation of what types of errors these options catch.
-ansi -pedantic
-Werror
-Wall
-Wall, but it is not enough on its own.
-O4
-Wall rely on the optimizer to analyze the code. If there is no
optimization then the warnings aren't generated.
-W
-Wall, such as
missing return values and comparisons between signed and unsigned
integers.
-Wmissing-prototypes -Wstrict-prototypes
-Wtraditional
-Wconversion
unsigned int x = -1. If you need
to perform such a conversion you can use an explicit cast.
-Wshadow
-Wpointer-arith -Wcast-qual -Wcast-align
void, if you remove a const
cast from a pointer, or if you cast a pointer to a type which has a
different size, causing an invalid alignment.
-Wwrite-strings
const qualifier so that it
will be a compile-time error to attempt to overwrite them.
-fshort-enums
enum as short as possible. Normally
this makes an enum different from an int. Consequently any
attempts to assign a pointer-to-int to a pointer-to-enum will generate a
cast-alignment warning.
-fno-common
extern declaration.
-Wnested-externs
extern declaration is encountered within an
function.
-Dinline=
inline keyword is not part of ANSI C. Thus if you want to use
-ansi with a program which uses inline functions you can use this
preprocessor definition to remove the inline keywords.
-g
gdb. The only effect of debugging symbols
is to increase the size of the file, and you can use the strip
command to remove them later if necessary.