What does "-wall" do in "g ++ -wall test.cpp -o test"?

-o changes the name of the output file (I found that using --help)

But I can’t find out what -Wall doing?

+57
c ++ g ++
Mar 09 '10 at 9:53
source share
7 answers

This is short for β€œwarn all” - it includes (almost) all warnings that g ++ can talk about. This is usually a good idea, especially if you are a beginner, because understanding and correcting these warnings can help you solve many different problems in your code.

+72
Mar 09 '10 at 9:55
source share

See man gcc.

-Wall includes the following warnings:

 -Waddress -Warray-bounds (only with -O2) -Wc++0x-compat -Wchar-subscripts -Wenum-compare (in C/Objc; this is on by default in C++) -Wimplicit-int (C and Objective-C only) -Wimplicit-function-declaration (C and Objective-C only) -Wcomment -Wformat -Wmain (only for C/ObjC and unless -ffreestanding) -Wmissing-braces -Wnonnull -Wparentheses -Wpointer-sign -Wreorder -Wreturn-type -Wsequence-point -Wsign-compare (only in C++) -Wstrict-aliasing -Wstrict-overflow=1 -Wswitch -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunused-function -Wunused-label -Wunused-value -Wunused-variable -Wvolatile-register-var 

-Wextra contains:

 -Wclobbered -Wempty-body -Wignored-qualifiers -Wmissing-field-initializers -Wmissing-parameter-type (C only) -Wold-style-declaration (C only) -Woverride-init -Wsign-compare -Wtype-limits -Wuninitialized -Wunused-parameter (only with -Wunused or -Wall) -Wunused-but-set-parameter (only with -Wunused or -Wall) 

There are many other warnings that you must include explicitly.

eg. for our C code we use:

-Wall -Wextra -Waggregate-return -Wcast-align -Wcast-qual -Wdisabled-optimization -Wdiv-by-zero -Wendif-labels -Wformat-extra-args -Wformat-nonliteral -Wformat-security -Wformat- y2k -Wimplicit -Wimport -Winit-self -Winline -Winvalid-pch -Wjump-misses-init -Wlogical-op -Werror = missing-braces -Wmissing-declarations -Wno-missing-format-attribute -Wmissing-include-dirs - Wmultichar -Wpacked -Wpointer-arith -Wreturn-type -Wsequence-point -Wsign-compare -Wstrict-aliasing -Wstrict-aliasing = 2 -Wswitch -Wswitch-default -Werror = undef -Wno-unused -Wvariadic-macro -Wwrite- strings -W ++ - compat -Werror = declaration-after-statement -Werror = implicit-function-declaration -Wmissing-prototypes -Werror = nested-externs -Werror = old-style-definition -Werror = strict prototypes

+22
03 Sep '12 at 11:59
source share

It is sad enough that none of the answers cite the corresponding part of the manual, which really leads to a certain point:

This allows all warnings about constructs that some users consider dubious and that are easy to avoid (or modify to prevent warnings), even when combined with macros.

[...]

Note that some warning flags are not implied by -Wall . Some of them warn about constructions that users usually do not consider doubtful, but which you can sometimes check; others warn of constructions that are necessary or difficult to avoid in some cases, and there is no easy way to change the code to stop the warning. Some of them are included -Wextra but many of them must be included individually.

Ergo:

  • -Wall does not mean "all warnings."
  • It also does not mean "(almost) everything", not a long shot.
  • This means a set of individual parameters that may change.

Below, we are talking about the absolute minimum of warnings you should set. While -Wall -Wextra better, it still does not use all the error checking that your compiler can do for you.




Personally, I would not become smaller -Wall -Wextra -Wfloat-equal -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wmissing-declarations -Wredundant-decls -Wshadow -Woverloaded-virtual . All of my current projects actually use the alert list longer (without running any of them). And I check the manual for each major version for new parameters. The compiler is your friend. Use any diagnostics that he can offer you.

+13
Feb 06 '14 at 9:38
source share

It allows you to use warnings that are considered useful and easily fixed in the source by gcc writers. There is also -W (-Wextra in newer versions), which are considered useful, but for which avoiding false positives can be difficult or lead to awkward codes.

gcc also contains many other warnings, usually less useful. See http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Warning-Options.html#Warning-Options

+6
Mar 09 '10 at 10:09
source share

It allows all warnings. (read as "Warning All")

+1
Mar 09 '10 at 9:56
source share

This enables most warning messages .

You can learn more if you use g++ --help=warnings .

+1
Jan 17 '15 at 21:38
source share

All warnings are displayed here. I would also recommend using -pedantic to warn about some inappropriate parts of the code.

0
Mar 09 '10 at 9:57
source share



All Articles