Out of range pointers

Richard Harter g-rh at XAIT.XEROX.COM
Wed Sep 21 17:30:05 AEST 1988


In article <8544 at smoke.ARPA> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>In article <33547 at XAIT.XEROX.COM> g-rh at XAIT.Xerox.COM (Richard Harter) writes:
>>As a side note, one argument for making x[-1] legal is that it permits
>>you to use sentinels in both directions.  I don't see that this is a
>>problem, regardless of architecture.  All that is required is that nothing
>>be allocated on a segment boundary.

>There is a considerable practical difference between this case and the
>one for a pointer just past the last member of an array.  The [-1] case
>can require reservation of an arbitrary amount of unused address space
>below an actual object, whereas the other case requires no more than a
>byte (or a word, depending on the architecture) of space reserved above.

Good point.  [For those who didn't catch it, the size of the object that
a pointer is pointing to can be a structure of (arbitrary) size.  To allow
&x[-1] to be legal you have to leave enough space for an instance of the
structure (or array of structures or whatever) before the actual instance.]

Doug's claim that the other case (one past) need only require a word (or byte)
of memory at the end suggests a question that I don't know the answer to.
Suppose that x is an array of structures of length n.  As we all know, 
&x[n] is legal.  But what about &x[n].item?  If Doug's assertion is correct,
and I expect it is since he is quite knowledgable in these matters, then
it would seem to follow that &x[n].item is not guaranteed to be legal.



-- 

In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
	Richard Harter, SMDS  Inc.



More information about the Comp.lang.c mailing list