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: Bernard Dautrevaux <Dautrevaux at microprocess dot com>
- To: 'Tom Lord' <lord at emf dot net>, Bernard Dautrevaux <Dautrevaux at microprocess dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 18 Mar 2002 10:46:43 +0100
- Subject: RE: pointer <-> integer conversion warnings (bogus -Wall warnings )
> -----Original Message-----
> From: Tom Lord [mailto:lord@emf.net]
> Sent: Monday, March 18, 2002 10:25 AM
> To: Dautrevaux@microprocess.com
> Cc: gcc@gcc.gnu.org
> Subject: Re: pointer <-> integer conversion warnings (bogus -Wall
> warnings )
>
>
>
>
> Dautrevaux@microprocess.com
>
> I was just stressing that "x = (int)p" is NOT equivalent, in
> the standard, to "x = (int)((char *)p - (char *)0)" as you
> suggest,
>
> I did not suggest that those expressions were equivalent in any
> standard.
>
>
> Then, as you were looking at a portable way to silent this
> warning, I think it is relevant to note that the warning you
> want to silent has NO portable meaning
>
> No, that is not especially relevant. The question is whether a
> single, ordinary cast ought to be sufficient to mark the legal,
> non-portable construct as "intentional", and thus not worthy (under
> some combination of options) of warning.
The single cast can't be enough as, as I and others note already, at least
one cast is required to convert between pointer and integer in standard C.
The only implicit conversion existing between a pointer type and a scalar
type is between a NULL pointer and a ZERO integer. Note that the standard
does not even require that the bit representation of both aare identical, so
that we may have (per the standard, although I don't know of current
implementation where this is true):
p == 0 TRUE
p == (void*)0 TRUE
(int)p == 0 FALSE
Bernard
--------------------------------------------
Bernard Dautrevaux
Microprocess Ingenierie
97 bis, rue de Colombes
92400 COURBEVOIE
FRANCE
Tel: +33 (0) 1 47 68 80 80
Fax: +33 (0) 1 47 88 97 85
e-mail: dautrevaux@microprocess.com
b.dautrevaux@usa.net
--------------------------------------------