This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: pointer <-> integer conversion warnings (bogus -Wall warnings)
On 13-Mar-2002, Tom Lord <lord@emf.net> wrote:
>
> From: Richard Henderson <rth@redhat.com>
> On Wed, Mar 13, 2002 at 04:25:51PM -0800, Tom Lord wrote:
> > x = (int)(size_t) p;
> >
> > That double cast is not safe.
>
> Care to explain your reasoning?
>
> I'm sure we can all figure it out.
>
> Care to point to a system for which it fails?
>
> The one released in 2008 that has 64 bit pointers and integers with 32
> bit size_t.
I think it is unlikely that any such system will ever be released.
> > The simple rule that explicit casts to appropriate types don't
> > generate warnings in the absense of extraordinary options gives this
> > class of warnings a clear and useful relation to the various
> > standards. I don't understand why that rule is at all controversial.
>
> Because virtually all code that pointer to integer casts with "int"
> breaks on 64-bit targets. This is not speculation; this is hard
> experience bringing alpha-linux up from the first shell prompt.
I just want to say that I too found these warnings extremely useful when
porting Mercury and CLP(R) to a 64-bit target (dec-alpha-osf*).
I have also encountered a few false positives, but these are easy to
work around.
> The warning isn't going to change. It is going to remain enabled
> with no -W flags whatsoever. Live with it.
>
> To match your tone I guess I'd have to make fun of you for confusing
> "virtually all code" with "alpha-linux"
He didn't confuse those two. He said virtually all code that casts
from pointers to "int" breaks on [some] 64-bit targets. This is my
experience too.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.