Out of range pointers

Henry Spencer henry at utzoo.uucp
Tue Sep 20 07:30:23 AEST 1988


In article <33432 at cca.CCA.COM> g-rh at XAIT.Xerox.COM (Richard Harter) writes:
>In C a pointer is a fairly anonymous object.  What you are saying is
>that it is a potential error to add or subtract an integer from a
>pointer if the result is out of range.  Very well, but what is that
>range?

The members of the array that the pointer points into, plus the special
case of just above the end of the array.

>Suppose a pointer is passed through a calling sequence.  In
>the function I have no way of knowing whether &x[n] will break for any
>n other than 0.  For that matter I have no way of knowing whether 
>x is a legal pointer!

That's correct.  It is the caller's responsibility to supply a pointer
that is adequate for the function's purposes, and the function writer's
responsibility to document those purposes well enough that the caller
knows what his responsibilities are.  There is no way to check this at
runtime in conventional C implementations.  That's C for you.
-- 
NASA is into artificial        |     Henry Spencer at U of Toronto Zoology
stupidity.  - Jerry Pournelle  | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list