Where did the warning go?
Eivind LM
eivliste@online.no
Tue Feb 24 15:10:00 GMT 2009
On Tue, 24 Feb 2009 15:13:55 +0100, Tom St Denis
<tstdenis@ellipticsemi.com> wrote:
> 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.
I think the warning should be part of -Wall, but I understand if you don't
agree. Anyway this is not my point. I trust someone has good reasons for
the selection of warnings included in -Wall.
My points are: "-Wall" should be renamed, and a new flag should be added
that would enable absolutely all warnings.
> e.g.
>
> int a;
> if (a == 4) { ... }
>
> Is undefined behaviour since a is unitialized.
Compiling this example with -Wall and -Wextra gives me no warning with g++
(Debian 4.3.2-1.1) 4.3.2. Installed by apt-get today from Debian
repositories.
> 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.
Yes, I would like a warning if I compare a float to an int.
I would probably not compare two floats on equality anyway, but if I
really had to, then I would write "4" as 4.0f.
Compiling the second example with -Wall and -Wextra gives me no warning
with the same compiler as above.
> -Wall should really just enable every warning that has something to do
> with behaviour that is not predictable.
Fine, but the name should be changed.
> -Weverything would be an appropriate name for every warning.
Agree! :)
Eivind
More information about the Gcc-help
mailing list