This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Eivind LM wrote:It does of course depend on each case whether a warning is easy to avoid or not, and also if it warns about a real problem or not. But in any case, a warning can help me write code that more surely will do what I intend. For example the following code is not doing what I intended:That's because it's not undefined behaviour. "default" warnings should be for things that are not guaranteed to have a known meaning or behaviour.
#include <stdio.h> void print(int a) { printf("%d\n", a); }; int main() { print(2.5); return 0; };
I think the problem in the code is both easy to avoid and serious, but I get no warning with -Wall and -Wextra (g++ 4.3).
e.g.
int a; if (a == 4) { ... }
Is undefined behaviour since a is unitialized.
float a; a = 0; if (a == 4) { ... }
Is fine, but I should also point out "4" is an integral type that is converted to float for the purpose of the expression "a == 4" . So by your logic, it should also generate a warning.
-Wall should really just enable every warning that has something to do with behaviour that is not predictable.
-Weverything would be an appropriate name for every warning.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |