Re: C Fronts

henry@zoo.toronto.edu (Henry Spencer)
Fri, 9 Aug 1991 18:14:01 GMT

          From comp.compilers

Related articles
C Fronts whatis@gnu.ai.mit.edu (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 kers@hplb.hpl.hp.com (Chris Dollin) (1991-08-08)
Re: C Fronts henry@zoo.toronto.edu (1991-08-09)
| List of all articles for this month |
Newsgroups: comp.compilers
From: henry@zoo.toronto.edu (Henry Spencer)
Keywords: C, optimize
Organization: U of Toronto Zoology
References: 91-08-032
Date: Fri, 9 Aug 1991 18:14:01 GMT

In article 91-08-032 Chris Dollin <kers@hplb.hpl.hp.com> writes:
>...it is *not* legal to index an
>array outside its bounds in C. For example, ``a[10][-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, henry@zoo.toronto.edu utzoo!henry
[Norman Diamond <diamond@tkov50.enet.dec.com> also pointed this out. Clearly
I should put my copy of the standard back in the bathroom so I read it again.
-John]


--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.