This is the mail archive of the gcc@gcc.gnu.org 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 [mailto:lord@regexps.com]
> Sent: Friday, March 15, 2002 5:47 PM
> To: Dautrevaux@microprocess.com
> Subject: Re: pointer <-> integer conversion warnings (bogus -Wall
> warnings )
> 
> 
> 
>    From: Bernard Dautrevaux <Dautrevaux@microprocess.com>
>    > 	2. One intention of the default conversion in the language is
>    > 	   that, for a small enough, not necesarilly 0 integer, the
>    > 	   round trip will give the same integer.  It's hard to
>    > 	   imagine any implementation that won't, in fact, get this
>    > 	   "right", treating:
>    > 
>    > 			p = (void *)x;
>    > 
>    > 	   as equivalent to:
>    > 
>    > 			p = (void *)((char *)0 + x);
>    > 
>    > 	   and
>    > 
>    > 			x = (int)p;
>    > 
>    > 	   as equivalent to:
>    > 
>    > 			x = (int)((char *)p - (char *)0);
> 
>    This is plain wrong!
> 
>    The problem there is that (char*)p - (char*)0 is 
> EXPLICITELY defined as
>    undefined behaviour by the C standard: pointer arithmetic 
> is only allowed if
>    the two pointers point at the same "object"... 
> 
> You aren't reading the context very carefully if you think your reply
> is relevant.

I was just stressing that "x = (int)p" is NOT equivalent, in the standard,
to "x = (int)((char *)p - (char *)0)" as you suggest, and presenting example
of implementations where this could effectively be different.

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, especially for the cases where the proposed way to silent it may
not work.

	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
-------------------------------------------- 


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