|GNU Scientific Library Reference Manual - Third Edition (v1.12)|
by M. Galassi, J. Davies, J. Theiler, B. Gough, G. Jungman, P. Alken, M. Booth, F. Rossi
Paperback (6"x9"), 592 pages, 60 figures
RRP £24.95 ($39.95)
40.7 GCC warning options for numerical programs
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.
- Use ANSI C, and reject any non-ANSI extensions. These flags help in writing portable programs that will compile on other systems.
- Consider warnings to be errors, so that compilation stops. This prevents warnings from scrolling off the top of the screen and being lost. You won't be able to compile the program until it is completely warning-free.
This turns on a set of warnings for common programming problems. You
-Wall, but it is not enough on its own.
Turn on optimization. The warnings for uninitialized variables in
-Wallrely on the optimizer to analyze the code. If there is no optimization then these warnings aren't generated.
This turns on some extra warnings not included in
-Wall, such as missing return values and comparisons between signed and unsigned integers.
- Warn if there are any missing or inconsistent prototypes. Without prototypes it is harder to detect problems with incorrect arguments.
The main use of this option is to warn about conversions from signed to
unsigned integers. For example,
unsigned int x = -1. If you need to perform such a conversion you can use an explicit cast.
- This warns whenever a local variable shadows another local variable. If two variables have the same name then it is a potential source of confusion.
-Wpointer-arith -Wcast-qual -Wcast-align
These options warn if you try to do pointer arithmetic for types which
don't have a size, such as
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.
This option gives string constants a
constqualifier so that it will be a compile-time error to attempt to overwrite them.
This option makes the type of
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.
This option prevents global variables being simultaneously defined in
different object files (you get an error at link time). Such a variable
should be defined in one file and referred to in other files with an
This warns if an
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
It always makes sense to put debugging symbols in the executable so that
you can debug it using
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.
|ISBN 0954612078||GNU Scientific Library Reference Manual - Third Edition (v1.12)||See the print edition|