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)
- From: Tom Lord <lord at emf dot net>
- To: gcc at gcc dot gnu dot org
- Cc: dewar at gnat dot com, rth at redhat dot com
- Date: Wed, 13 Mar 2002 14:17:45 -0800 (PST)
- Subject: Re: pointer <-> integer conversion warnings (bogus -Wall warnings)
- References: <20020313000641.72845F2DD2@nile.gnat.com> <200203131212.EAA27998@morrowfield.home> <200203132159.NAA27786@emf.net>
I wrote:
rth suggests:
x = (void *)(size_t)y
and I think that's pretty nice. One can safely assume that
`size_t' is small enough not to overflow a pointer type and
the double cast (aside from being easy to grep for) means
"Yes, I really mean to truncate the integer if necessary
before casting it to a pointer."
On second thought -- is there really any such guarantee?
There is certainly a reasonable assumption that the values returned by
`sizeof' or `read' won't overflow a pointer, but can't `size_t' have a
larger range overall?
If so, while the double cast will work on most platforms, there can be
reasonable platforms on which it won't eliminate the warning.
So I'm back to thinking that in the presence of an explicit cast,
-Wall shouldn't give warnings about pointer <-> integer conversions at
all. That's exactly what a cast for a conversion that happens by
default means.
-t