Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

g++

-o changes the output filename (I found that using --help)

But I can't find out what -Wall does?

like image 927
steven Avatar asked Mar 09 '10 09:03

steven


People also ask

What does Wall in c mean?

-Wall means to enable all compiler warnings. And -Werror means treat all warnings as errors.

What does GCC O do?

gcc -o writes the build output to an output file. gcc -O sets the compiler's optimization level.

What is the purpose of the G flag in g ++?

(debug) Inserting the `g' flag tells the compiler to insert more information about the source code into the executable than it normally would. This makes use of a debugger such as gdb much easier, since it will be able to refer to variable names that occur in the source code.


2 Answers

It's short for "warn all" -- it turns on (almost) all the warnings that g++ can tell you about. Typically a good idea, especially if you're a beginner, because understanding and fixing those warnings can help you fix lots of different kinds of problems in your code.

like image 155
Tyler Avatar answered Sep 20 '22 08:09

Tyler


See man gcc.

-Wall turns on these 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 more warnings which you have to turn on explicitly.

E.g. 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-macros -Wwrite-strings -Wc++-compat -Werror=declaration-after-statement -Werror=implicit-function-declaration -Wmissing-prototypes -Werror=nested-externs -Werror=old-style-definition -Werror=strict-prototypes

or just the set of warnings with https://www.gnu.org/software/autoconf-archive/ax_compiler_flags.html

like image 22
rurban Avatar answered Sep 20 '22 08:09

rurban