detecting invalid pointers

Joe English jeenglis at nunki.usc.edu
Fri Mar 17 15:21:23 AEST 1989


karl at haddock.ima.isc.com (Karl Heuer) writes:
>In article <3011 at nunki.usc.edu> jeenglis at nunki.usc.edu (Joe English) writes:
>>karl at haddock.ima.isc.com (Karl Heuer) writes:
>>>This works because pointer *equality* is well-defined even on pointers into
>>>different arrays.
>>
>>Well, maybe not... [80x86 in large model with unnormalized pointers]
>
>If the compiler ever generates unnormalized pointers, then it had better be
>prepared to generate code to compare them correctly.

You're right, but Turbo C (and probably MSC as well)
don't bother to most of the time.  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 -- which
isn't that bad, since that's a meaningless comparison
to start with -- or for a normalized (cast to huge *)
pointer to test unequal to the equivalent
non-normalized value -- which can cause problems
and is one of the many reasons why I don't use
'large' model.

(According to the TC documentation, pointers cast
 to huge or in the huge model always compare correctly,
 but the execution speed suffers terribly.)

--Joe English

  jeenglis at nunki.usc.edu



More information about the Comp.lang.c mailing list