detecting invalid pointers
Kevin_P_McCarty at cup.portal.com
Kevin_P_McCarty at cup.portal.com
Mon Mar 20 16:47:02 AEST 1989
In <3092 at nunki.usc.edu>, jeenglis at nunki.usc.edu (Joe English) writes:
>Since in 'large'
>model all arrays have to fit in the same segment, any
>two pointers calculated from the base of the array can
>be compared just by their offsets. In normal usage,
>this isn't a problem; however, it is possible for two
>pointers into *different* arrays to test equal
Not true. I just tried it. The <, <=, >= and > comparisons
use only the offset parts of the pointers, but == looks
at both segment and offset when pointers are 32 bits.
This is also documented in the manual (User's Guide v2.0, p.346).
It is possible however to have two pointers point to the same storage
location but which compare unequal. A one-to-one mapping between
pointers and storage locations is not required.
Not only is it true that pointers are not ints, they don't even
behave like ints.
Kevin McCarty
More information about the Comp.lang.c
mailing list