RG <rnospa...@flownet.com> writes: > In article <slrniaa0gi.6t7.usenet-nos...@guild.seebs.net>, > Seebs <usenet-nos...@seebs.net> wrote: > >> On 2010-09-30, RG <rnospa...@flownet.com> wrote: >> > That gives (what I would consider to be) false positives, e.g.: >> >> > [...@mighty:~]$ cat foo.c >> >> > void foo(long x) {} >> >> > int main() { foo(1); } >> > [...@mighty:~]$ gcc -Wconversion foo.c >> > foo.c: In function ???main???: >> > foo.c:4: warning: passing argument 1 of ???foo??? with different width due >> > to prototype >> >> But it's *not* a false positive. The compiler is not claiming that the >> conversion couldn't be done -- it's just telling you that there is a >> change of type going on. > > Again, you can't have it both ways. Either a warning is a "compiler > error" according to the claim at issue (see below) or it is not. If it > is, then this is a false positive. If it is not, then my previous > example refutes the claim. [...]
In this case, the conversion (from int to long) cannot fail (barring undefined behavior elsewhere in the program), because long is guaranteed to be able to hold any value within the range of int. It would be reasonable, at least as an option, to warn only about conversions that can fail, or only about conversions that can lose information, perhaps distinguishing between implicit conversions and explicit conversions (casts). Even the warning about foo(1) is not entirely unreasonable; some programmers might prefer to write foo(1L) rather than foo(1), to make it clear that the argument being passed is of type long rather than int. I don't know whether gcc provides this level of control over which conversions it warns about, but again, that's a gcc issue, not a C issue. -- Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" -- http://mail.python.org/mailman/listinfo/python-list