¿Qué indicadores de GCC utilizan los principales proyectos de código abierto para controlar el comportamiento indefinido en C y C ++? [cerrado]

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:

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 el porqué?

preguntado el 01 de febrero de 12 a las 22:02

Te refieres a -Wall -Wextra -Wshadow -Weffc++ -Wstrict-aliasing -ansi -pedantic -Werror -Wunreachable-code to show all the warning for undefined behavior and making them errors. -

I think commonly used might be interpreted as "How do most of you do this?" -

What @Nicol said. If you don't want hechos, pero prevailing opinion, then you're in the wrong place. SO is not a forum. -

@wjl: That doesn't really help. A survey of the compile flags for "major open source projects" is a poll. And what constitutes a "major" project? Notice that the question has already attracted 2 answers that completely miss the point. So no, I don't see this as being an improvement. -

@LightnessRacesinOrbit: So what? Because there hasn't been a cw question for a long time means there's never going to be one again? A quick search on meta didn't show any hints that cw is discouraged. -

2 Respuestas

-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.

Respondido 02 Feb 12, 02:02

Personally the most important one is:

  • -Werror

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:

  • -Pared
  • -Wextra

To force myself to standards comliand and thus make the code as portable as possable

  • -pedante
  • -ansi

I like S.Myers books so I add

  • -Weffc ++

But unfortunately not all the libraries I use work well with this. So I turn it off a bit.

Respondido 02 Feb 12, 02:02

+100 for -Werror. Look at every warning people. Fix them all. If it is a genuine false alarm, #pragma it out. One warning in the build log is one warning you have ignorado, or it wouldn't be there. (You rebuilt to check they were all gone, didn't you?) - Ben

I don't think that this answers the question at all. - Carreras de ligereza en órbita

@LightnessRacesinOrbit: Yep. Flip answer to bad question. I hope it is useful to somebody. - Martin York

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.