For tuning GCC flags for a particular application, see http://opentuner.org/
What Are Your GCC Flags?
11–20 of 117 posts
Re: What Are Your GCC Flags?
#12Re: What Are Your GCC Flags?
#13Personally I consider "-Werror" stupid. Warnings are designed to help and be reviewed, but aiming at "100% warning free" code should not be an "aim". For instance, I'd rather have "unitialized warnings" than use "i = i", which you know, might actually be correct code if "i" was available in scope and you want an additional copy that you can modify (nester for loops come to mind).
I sometimes leave warnings when silencing them "uglifies" the code.
"-fvisibility=hidden" is not so easy to leave on all the time when building software build by others. What I use is mostly "-fvisibility-inlines-hidden" in C++ code, even when building OSS projects, for which I never had a problem so far (in c++ inlines _are_ expected to have hidden visibility).
I also use "-march=native -flto=jobserver" and "-fwhole-program" (when linking) when I'm targetting my own hardware.
I also noticed that gcc now supports "-Og" to build optimized programs without impact on debugging, for which I had a very long command line before. "-Og -g3" gives pretty decent performance and optimal debugging, which is ideal for beta-testing programs.
gcc supports a pretty infinite list of command line switches. Actually, if you know what you are doing, you can optimize a program so well it's pretty much impossible to beat even by hand-crafting assembly. I know I tried several times, before realizing I could move a function to a separate object and supply a different set of optimization flags tuned just for that function.
For instance, "-Ofast" is actually safe most of the time for system utilities (and most other OSS software), and gives quite a boost for programs working with floats (most image-resizing loops and the like). Very few programs actually rely on exact IEEE arithmetic. Though I never use it, since finding issues might be _very_ hard.
Re: What Are Your GCC Flags?
#14 -Os
Then if any functions are a bottleneck, compile them with function-specific O2 or O3.Re: What Are Your GCC Flags?
#15-fno-exceptions I don’t like C++ exceptions. And we don’t use them where I work And none of your code uses the STL nor third party libraries that might throw exceptions either, right [1] [1] "Doing without" http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_excepti...
Most code can use -fno-rtti Real Time Type Info
Re: What Are Your GCC Flags?
#16"-Winit-self" actually disables the common "var x = x" idiom which is used to silence "uninitialized variable" warnings. Personally I consider "-Werror" stupid. Warnings are designed to help and be reviewed, but aiming at "100% warning free" code should not be an "aim". For instance, I'd rather have "unitialized warnings" than use "i = i", which you know, might actually be correct code if "i" was available in scope a…
so now we have a flag that disables a hack in code that is used to disable a warning caused by another flag. This is about as ridiculous to my (untrained in C) mind as it is to have -Wall not in-fact turn on all warnings.
Re: What Are Your GCC Flags?
#17 -Werror
is fine on your dev machine, but is a very bad idea in the official build system, notably if you do it for a library that you want people to use.As soon as you want to compile with various compilers, systems, use cross-compilation and other funny things that makes it portable, you're going to have a bad time.
New compilers will make new warnings, old compilers will make new warnings, clang and gcc have different warnings. Different distributions with gcc compiled with different flags will make different warnings too!
And of course, I don't mention libraries (or Mingw) that will always warn because of warnings inside their headers (I'm looking at you Fribidi).
Re: What Are Your GCC Flags?
#18Because it makes things a lot easier when writing cross platform code besides when using MSC, as that is the ugly sister.
Re: What Are Your GCC Flags?
#19This is probably an unpopular opinion, but: -Werror is fine on your dev machine, but is a very bad idea in the official build system, notably if you do it for a library that you want people to use. As soon as you want to compile with various compilers, systems, use cross-compilation and other funny things that makes it portable, you're going to have a bad time. New compilers will make new warnings, old compilers will…