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)
Date: Wed, 13 Mar 2002 17:49:16 -0500
From: Tim Hollebeek <tim@hollebeek.com>
> There is no integer type guaranteed to be wide enough to hold values
> from pointers. So unlike the first warning I asked about, I don't see
> any reasonable "double cast" that solves the problem.
Why not:
x = (int)(intptr_t)p;
Because it is certainly not portable and is not as nearly as I can
tell, part of ISO/IEC 9899:1990 or IEEE 1003.1-1990.
A good heursitic for portable code is when there is agreement (on the
topics they all cover) between:
"The Standard C Library" (Plauger 1992)
"Posix Programmer's Guide" (Lewin 1991-1994)
"C, A Reference Manual" (Harbison & Steele, fourth edition, 1995)
The last book, in particular, observes "Some computers may have
pointer representations that are longer than the largest integer
type" and I'm inclined to go with that.
-t