public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Re: Where did the warning go?
@ 2009-02-25  0:23 Tom St Denis
  2009-02-25 13:53 ` Eivind LM
  0 siblings, 1 reply; 29+ messages in thread
From: Tom St Denis @ 2009-02-25  0:23 UTC (permalink / raw)
  To: Tom St Denis, Eivind LM; +Cc: gcc-help

On Tue 24/02/09  7:09 PM , "Eivind LM" eivliste@online.no sent:
> I'm sure there are several opinions on what "annoying" and "useless"  
> warnings are. A warning can only annoy me if I don't do anything about it. 
> And "unlikely to be wrong" is not sufficient for me to consider the  
> warning to be useless.
> 

Yeah, the problem is you can have warnings for things that don't need warnings. 
Like for example:

int a;
a = 4;

warning:  the variable name "a" is too short, and doesn't contain the letter 'e'

Is a "valid" warning, since a conforming compiler may produce ANY warning it want
(the spec only specifies what warrants a diagnostic (error)).  Now if GCC emitted
that warning would you find that useful?  Or perhaps would it get in the way of
real work?

Now onto something less trivial ...

char a = 'b';

You're assigning an "int" type to a char.  splint will warn you about this, even
though it's perfectly reasonable and well understood [not to mention portable]
code.  Is that useful?

In your own example passing 2.5 to a function declared with an int parameter. 
That has well defined behaviour as well.  It's no less defined than say passing
"5" to a function that accepts a long.

> I take all warnings as an opportunity to learn some specific details about 
> the language. I am a novice, and trust the GCC developers have a good  
> reason to write each warning. It is usually easy to get the idea of the  
> possible problem when a warning triggers in my own code. Then I either  
> find out that the problem can absolutely never ever affect me (and then I  
> would disable the warning), or I change my code. I have never been sure  
> enough yet to disable any of the warnings I have seen so far.

The goal of good warnings is to detect things that are likely to be bugs, or are
at least undefined behaviour.  Not to warn about things that have clearly defined
behaviours.  If you want to learn more about C, pick up the ISO C draft and read
it.  Don't rely on the warnings from GCC to teach you what is and isn't good C code.
 
> I do of course think differently if I work with old code that has too many 
> warnings to fix. But encouraging everyone to compile their new code with  
> as many warning flags as possible could eventually solve that problem? :)

It is indeed a good goal to have warning free code, but adding mindless and
useless casts everywhere (for instance) is just as annoying coding practice.  I
wouldn't accept code that read, like

char a = (char)'b';

As it's superfluous and will make reading the code harder, not easier.

It's why a lot of people avoid tools like splint (if their corporate masters
don't dictate it's use) because 99 out of 100 times the warnings produced don't
lead to anything that could even remotely possibly be a bug.  It's irresponsible
to trace down and "fix" what isn't broken.  Specially when there are better tools
out there like valgrind to help debug your apps.

> Anyway, we don't have to agree on this. I just wish to have a flag that  
> let me compile my own code with as many warnings as possible. And then the 
> name of the -Wall flag is in the way.

I'm trying to help you by persuading you that that's not a good idea.  Learn the
C standard and code within it's boundaries.  Don't rely on superfluous warnings
to avoid bugs because at the end of the day it's not a sufficient condition for
bug free code to be splint warning free.

Tom

^ permalink raw reply	[flat|nested] 29+ messages in thread
* Where did the warning go?
@ 2009-02-13 16:07 Eivind Lyche Melvær
  2009-02-13 16:27 ` John (Eljay) Love-Jensen
  0 siblings, 1 reply; 29+ messages in thread
From: Eivind Lyche Melvær @ 2009-02-13 16:07 UTC (permalink / raw)
  To: gcc-help

Greetings,
The code below used to (and should, in my opinion) generate a warning  
about implicit conversion. I have tried four different versions of g++:

   g++ 4.1.3 20080704 (prerelease) (Debian 4.1.2-25)
   g++ 4.2.4 (Debian 4.2.4-6)
   g++ 4.3.2 (Debian 4.3.2-1.1)
   g++ 4.3.3

Only the oldest version (4.1.3) gives me the warning that I'm after:

   warning: passing ‘double’ for argument 1 to ‘void print(int)’

The other three versions give no warning at all, even though I compile  
with -Wall and -Wextra. So it looks like the warnings disappeared  
somewhere after version 4.1.3. Is this a bug? Or is there a way to enable  
these warnings in the more recent versions of g++?

Thanks,
Eivind LM


#include <iostream>

void print(int number) {
   std::cout << number << std::endl;
}

int main() {

   double d = 1.5;
   print(d);
   return 0;

}

^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2009-02-25 21:48 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-25  0:23 Re: Where did the warning go? Tom St Denis
2009-02-25 13:53 ` Eivind LM
2009-02-25 14:20   ` Tom St Denis
2009-02-25 15:56     ` Eivind LM
2009-02-25 16:16       ` Tom St Denis
2009-02-25 17:16         ` John Z. Bohach
  -- strict thread matches above, loose matches on Subject: below --
2009-02-13 16:07 Eivind Lyche Melvær
2009-02-13 16:27 ` John (Eljay) Love-Jensen
2009-02-13 17:57   ` Eivind LM
2009-02-14  2:25     ` Ian Lance Taylor
2009-02-20 15:39       ` Eivind LM
2009-02-20 16:21         ` John (Eljay) Love-Jensen
2009-02-23 20:39         ` Ian Lance Taylor
2009-02-24 14:03           ` Eivind LM
2009-02-24 14:13             ` Tom St Denis
2009-02-24 15:10               ` Eivind LM
2009-02-24 18:29                 ` Tom St Denis
2009-02-25  0:07                   ` Eivind LM
2009-02-24 15:43             ` John (Eljay) Love-Jensen
2009-02-24 15:52               ` Kevin P. Fleming
2009-02-24 17:52             ` Ian Lance Taylor
2009-02-24 17:58               ` Harvey Chapman
2009-02-25  0:23                 ` Eivind LM
2009-02-25 12:09                   ` Tom St Denis
2009-02-25 12:25                     ` John (Eljay) Love-Jensen
2009-02-25 13:02                       ` Tom St Denis
2009-02-25 13:17                       ` Andrew Haley
2009-02-25 21:48                       ` Ian Lance Taylor
2009-02-25  0:37               ` Eivind LM

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).