Let's look at a few flags to control the level of warning we can
control. Listed here are some of the more useful and commonly used
warning options; if you want to view the full set of warnings available,
the GCC man
pages contain much more information.
All of the warning options are prefixed by -W
. So (for example)
-Wall
literally stands for all warnings, and is not some
euphemism for a wall!
-w
| Inhibit all warning messages.
|
-pedantic
| Print all warnings that are required by ANSI standard C.
|
-pedantic-errors
| Like -pedantic , except that the warnings are instead treated
as errors.
|
-Wall
| This a very general warning option: it encompasses a whole range of
features, each of which are listed below in following -W...
options1:
|
-Wimplicit-int
| Any function declarations without a return-type will be reported; their
return type will default to int .
|
-Wimplicit-function-declaration
| Warns whenever a function is encountered in a block of code, but has not
yet been declared.
|
-Wimplicit
| Same as -Wimplicit-int -Wimplicit-function-declaration .
|
-Wmain
| Warns if main :
- takes any other arguments other than (a) an - returns any value other than |
-Wreturn-type
| This flag warns that any function not declaring a return-type defaults
to int , and also warns of any non-void functions that do not
return a value.
|
-Wunused
| Warns if any:
- local variable is declared but not used; - a static function is defined, but is not used; or - a statement computes a result, but the result is never used.
|
-Wswitch
| Warns if
- an enumeration is used in a switch statement, but at least one of the elements of the enumeration has not been used in the switch; or - some value not catered for by the enumeration is used in the same
switch statement.
|
-Wcomment
| Warns if any comment started with /* contains an inner /* ;
for example, /* some comment... /* */ .
|
-Wformat
| If any print-related functions are called (for example printf ),
type-mismatching of arguments is reported where it occurs.
|
-Wchar-subscripts
| -
|
-Wuninitialized
| An automatic variable is used without first being initialized.
|
-Wparentheses
| Warns if parentheses are omitted in certain contexts.
|