This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: pointer <-> integer conversion warnings (bogus -Wall warnings )

> -----Original Message-----
> From: Tom Lord []
> Sent: Monday, March 18, 2002 10:25 AM
> To:
> Cc:
> Subject: Re: pointer <-> integer conversion warnings (bogus -Wall
> warnings )
>        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 Dautrevaux
Microprocess Ingenierie
97 bis, rue de Colombes
Tel:	+33 (0) 1 47 68 80 80
Fax:	+33 (0) 1 47 88 97 85

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]