Pointer Comparison and Portability

drw at cullvax.UUCP drw at cullvax.UUCP
Fri Feb 20 02:07:56 AEST 1987


john at viper.UUCP (John Stanley) writes:
>   Tom, on segmented arcitecture machines you -could- have two distinctly
> different pointer values which point to the same memory space.  This is
> what Israel Pinkas was (I think) trying to point out.
> 
>   In the example he gave:
> 	  char p[16], q[16];
> (Details of 8086 memory addressing omitted.)
> The byte of memory addressed by q[0] and p[17] would
> be the exact same byte, but the two pointers 0002:0000 and 0001:0010 would be
> different.

Yes, but comparing &p[17] and &q[0] is comparing two addresses derived
from different allocations, and as the standard says, that is
implementation defined (i.e., may not work).  Note also that &p[17] is
a correct *pointer*, but attempting to fetch or store anything through
it is not.  &p[18] is not a correct pointer.

Dale
-- 
Dale Worley		Cullinet Software
UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw
ARPA: cullvax!drw at eddie.mit.edu



More information about the Comp.lang.c mailing list