Hi,
I am a newbie in C++ programming. When compiling I never use any option.
This is my day to day command:
g++ MyCode.cc -o MyCode
For safety practice what's the best option to use?
-
“-Werror”: treats all warnings as errors so you have to fix them. Incredibly valuable.
Greg Hewgill : Along with -Wall to turn on all the useful warnings, of course. -
Actually, it's a set:
-Wall -pedantic -std=c++98
-
g++ -W -Wall -Werror
Will display all errors and warnings possible and treat them as errors.
eduffy : To the OP - Do what this poster suggests! You will save yourself many headaches if you just listen to the compiler warnings. Do not ignore them!Steve Jessop : Actually, it doesn't enable all possible warnings. -Wwrite-strings and -Wconversion are good too. -
g++ -Wall -Weffc++ -Werror -pedantic
When I'm using Boost, though, I drop it down to:
g++ -Wall -Werror
I'm anxiously awaiting GCC 4.4 and 4.5, though. There are some features coming that I really badly need.
Ned : What are the 4.4/4.5 features you're waiting for?greyfade : Lambdas (which I'm hoping show up in 4.5), auto variables (4.4), strongly-typed enums (4.4), and, most importantly, atomic<>, which I'm desperately hoping gets done in 4.5.Tom : Unfortunately, -Weffc++ makes objects with internal pointers a nightmare.greyfade : I know. That's why I don't use it with Boost - just including a Boost header creates another 30-40 warnings. -
g++ -g
I really need that debug information....
-
If you thought you caught everything, try
-Wextra
-
-pipe, it speeds up compilation a little bit. Also -O2, which speeds up execution.
Calyth : Optimization will generally interfere with debugging. For a newbie, using the -g and without -Ox would be preferable.Tom : What speed improvements have you seen with -pipe? I find it doesn't make a significant difference, as the bulk of the time is spent linking (which can't be parallelized across multiple cores, like compilation). -
I like
-march=athlon -O2 -pipe
for building most programs (I run Gentoo at home), and I use-ansi -pedantic -Wall
for code I write myself. -
We always use
g++ -Wall -Wextra ...
-
-ansi -pedantic
-D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -D_REENTRANT
-Wall -Wextra -Wwrite-strings -Winit-self -Wcast-align -Wcast-qual -Wold-style-cast -Wpointer-arith -Wstrict-aliasing -Wformat=2 -Wuninitialized -Wmissing-declarations -Woverloaded-virtual -Wnon-virtual-dtor -Wctor-dtor-privacy -Wno-long-long
-O3 -ftree-vectorize -ftree-vectorizer-verbose=2 -ffast-math -fstrict-aliasing -march=native/pentium4/nocona/core2 -msse2 -mfpmath=sse
0 comments:
Post a Comment