There are a handful of GCC flags that are used by major open-source projects to work-around perceived over-eagerness on the part of the compiler when handling undefined behavior, specifically in the C and C++ languages. For example:
-fno-strict-aliasing is a staple for those who want "traditional" behavior when type punning. For example: https://lkml.org/lkml/2003/2/26/158
-fwrapv is commonly used when wanting to have known behavior for signed overflow. For example: http://archives.postgresql.org/pgsql-hackers/2005-12/msg00635.php
What other ones are there? I obviously can get the full list from the GCC documentation of what flags turn what undefined behavior into what kind of implementation-defined behavior. However, I'm more interested in which options are used by major open-source projects and why?
-D_GLIBCXX_DEBUG is not exactly a compiler flag but it enables checked STL iterators and other goodies.
std::vector<int> v(42);
v[42] = 1; //The standard says this is UB. With checked iterators you will get a run-time exception.
Personally the most important one is:
This forces me to fix all warnings (as warnings are really logical errors).
Then I try and turn on as many of the default warnings with:
To force myself to standards comliand and thus make the code as portable as possable
I like S.Myers books so I add
But unfortunately not all the libraries I use work well with this. So I turn it off a bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With