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 -Wconversion -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wnested-externs -fshort-enums -fno-common -Dinline= -g -O2
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.
-Wall, but it is not enough on its own.
-Wallrely on the optimizer to analyze the code. If there is no optimization then these warnings aren't generated.
-Wall, such as missing return values and comparisons between signed and unsigned integers.
unsigned int x = -1. If you need to perform such a conversion you can use an explicit cast.
-Wpointer-arith -Wcast-qual -Wcast-align
void, if you remove a
constcast from a pointer, or if you cast a pointer to a type which has a different size, causing an invalid alignment.
constqualifier so that it will be a compile-time error to attempt to overwrite them.
enumas short as possible. Normally this makes an
enumdifferent from an
int. Consequently any attempts to assign a pointer-to-int to a pointer-to-enum will generate a cast-alignment warning.
externdeclaration is encountered within a function.
inlinekeyword is not part of ANSI C. Thus if you want to use
-ansiwith a program which uses inline functions you can use this preprocessor definition to remove the
gdb. The only effect of debugging symbols is to increase the size of the file, and you can use the
stripcommand to remove them later if necessary.