detecting invalid pointers

Chip Salzenberg chip at ateng.ateng.com
Tue Mar 21 23:57:03 AEST 1989


According to jeenglis at nunki.usc.edu (Joe English), referring to
normalizing 80x86 segment+offset pointers before comparing them:

>Turbo C (and probably MSC as well) don't bother to most of the time.  [...]

Quite true.  For totally correct comparisons of all pointers, it's necessary
to normalize them by hand, or be sure that they are cast to "huge *" when
any pointer arithmetic is done.  Otherwise, the different combinations of
segment+offset that actually refer to the same address do not compare equal.

>it is possible for two pointers into *different* arrays to test equal [...]

Fortunately, this is false.  Comparisons of *magnitude* only examine the
offset -- which is OK.  Comparisons of *equality* examine both the segment
and offset -- otherwise, any pointer with an offset of zero would compare
equal to NULL.

For understanding compiler options and non-standard keywords, there's no
substitute for looking at the assembler output of a compiler.  Yes, the
documentation is the definitive guide, but looking at the assembler output
is a wonderful aid in understanding what the documentation means.  :-)
-- 
Chip Salzenberg             <chip at ateng.com> or <uunet!ateng!chip>
A T Engineering             Me?  Speak for my company?  Surely you jest!
	  "It's no good.  They're tapping the lines."



More information about the Comp.lang.c mailing list