ANSI C, hardware protection, out-of-bounds pointers

Henry Spencer henry at utzoo.uucp
Wed Sep 6 03:54:11 AEST 1989


In article <427 at maytag.waterloo.edu> lhf at aries5 (Luiz H. deFigueiredo) writes:
>ANSI C says that is *is* legal to use mention (but not dereference) a pointer
>just out-of-bounds [on the high end]...
>Now I ask, it is possible/legal to do the analogous thing for a-1 ...

No.

High-end out-of-bounds pointers are very common, and all an implementation
usually has to do to make them work is to ensure that the end of the array
is at least one byte below a segment boundary (assuming that the hardware
has segments), so that a high-end pointer is still in the same linear
address space as a normal one and address arithmetic therefore works as
expected.  Low-end out-of-bounds pointers are much less common, and making
them work would typically require that the beginning of the array be at
least one array-element-size after a segment boundary... which can get
expensive if the elements are big.  The asymmetry is because a pointer to
an object generally points to its beginning.

It was felt (I am told) that the cost:benefit ratio was favorable for
high-end but not for low-end.  So it is not legal or portable to do this
for a-1.  (Whether it is possible is implementation-dependent.)
-- 
V7 /bin/mail source: 554 lines.|     Henry Spencer at U of Toronto Zoology
1989 X.400 specs: 2200+ pages. | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.std.c mailing list