Re: Where did the warning go?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:

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

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.

Tom

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux