detecting invalid pointers

Barry Margolin barmar at think.COM
Thu Mar 9 03:50:16 AEST 1989


I don't think it is possible to do what you want.  C only defines the
result of pointer less-than and greater-than comparisons when the
pointers are to the same array.

It's easy to imagine an implementation where A < P && P < A+N, yet P
is not a pointer into the array A[N].  If the system is segmented, and
arrays are required to fit within a single segment, the comparison
operations might only compare the offset portion of a pointer.  If A
were at seg1:100, N were 100, and P were seg2:150, the comparison
would be implemented as 100 < 150 && 150 < 200.

Barry Margolin
Thinking Machines Corp.

barmar at think.com
{uunet,harvard}!think!barmar



More information about the Comp.lang.c mailing list