|C Fronts email@example.com (1991-08-04)|
|Re: C Fronts MASLOV@VADIK.srcc.msu.su (1991-08-05)|
|Re: C Fronts MASLOV@VADIK.srcc.msu.su (1991-08-07)|
|Re: C Fronts firstname.lastname@example.org (Chris Dollin) (1991-08-08)|
|Re: C Fronts email@example.com (1991-08-09)|
|From:||firstname.lastname@example.org (Henry Spencer)|
|Organization:||U of Toronto Zoology|
|Date:||Fri, 9 Aug 1991 18:14:01 GMT|
In article 91-08-032 Chris Dollin <email@example.com> writes:
>...it is *not* legal to index an
>array outside its bounds in C. For example, ``a[-1]'' is illegal, even
>though blindly performing the address calculation would get a reference
>inside the array.
This is not quite correct. C array indexing is defined in terms of adding
integers to pointers. (a[b] is *(a + b) by definition.) The results of
taking a pointer outside the array by this means are undefined -- not
"illegal", but "undefined", meaning that what happens is entirely the
compiler's choice. (There is one obscure exception, which I omit for
clarity.) Relying on undefined behavior is unwise, and the compiler is
technically allowed to reject such a program, but it is not required to
do so. In the example, it may quite legitimately generate code that does
indeed give you a reference within the array, without any complications.
Such a compiler is not defective.
Henry Spencer @ U of Toronto Zoology, firstname.lastname@example.org utzoo!henry
[Norman Diamond <email@example.com> also pointed this out. Clearly
I should put my copy of the standard back in the bathroom so I read it again.
Return to the
Search the comp.compilers archives again.