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] |
On Tue, 24 Feb 2009 15:13:55 +0100, Tom St Denis <tstdenis@ellipticsemi.com> wrote:Because warnings for things that have defined behaviour [and aren't specifically likely to be wrong] are annoying, see "splint" for examples of useless warnings.
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).
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.
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.
Why? It's perfectly valid (well yeah not the == bit, but try a > 4).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.
long a; a = 3;
I dunno, there are a lot of people who use -Wall -W and rely on the fact that the warnings it produces are USEFUL not just chatty.-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.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |