Bounds checks. (was variable-length struct hack)
Theo Norvell
norvell at csri.toronto.edu
Tue Dec 12 10:16:31 AEST 1989
In article <1989Dec8.161820.24804 at jarvis.csri.toronto.edu> norvell at csri.toronto.edu (I) write:
>The drafts were not very explicit on this point [bounds checks], but when
>I was writing a compiler that did bounds checks, I read the then current
> draft and came to the following conclusion. [nonsense omitted]
After looking at a more recent draft (May 88) I found that (at least) 3 things
I said were either out of date or plain wrong. Let me make amends by saying:
(1) The draft is very explicit (3.3.6) that bounds checking is allowed.
(2) Even creating a pointer that points out of the array is
undefined with the exception of the pointer just past the end.
(3) Merely dereferencing the just past the end pointer is undefined,
not as I said loading or storing the resultant lvalue (although
that is naturally undefined too). Thus
int A[N], *p;
for(p=A; p < A+N ; ++p ) { ... } /* Good */
for(p=A; p < &A[N] ; ++p ) { ... } /* Undefined! */
Theo Norvell
More information about the Comp.std.c
mailing list