Pointer Comparison and Portability
franka at mmintl.UUCP
franka at mmintl.UUCP
Tue Feb 24 06:09:06 AEST 1987
In article <814 at cullvax.UUCP> drw at cullvax.UUCP writes:
>john at viper.UUCP (John Stanley) writes:
>> 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.
Actually, of course, it is p[16] which is equal to q[0], and &p[17] which is
not a correct pointer. Isn't zero-based array indexing wonderful? (:-)
Frank Adams ihnp4!philabs!pwa-b!mmintl!franka
Ashton-Tate 52 Oakland Ave North E. Hartford, CT 06108
More information about the Comp.lang.c
mailing list