Path: utzoo!utgpu!utcsri!norvell From: norvell@utcsri.UUCP (Theodore Stevens Norvell) Newsgroups: comp.lang.c Subject: Re: Is &a[NTHINGS] legal Message-ID: <5997@utcsri.UUCP> Date: 1 May 88 21:37:19 GMT Article-I.D.: utcsri.5997 Posted: Sun May 1 17:37:19 1988 References: <12074@tut.cis.ohio-state.edu> <11289@mimsy.UUCP> Reply-To: norvell@utcsri.UUCP (Theodore Stevens Norvell) Organization: CSRI, University of Toronto Lines: 18 Summary: In article <11289@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >In article <12074@tut.cis.ohio-state.edu> lvc@tut.cis.ohio-state.edu >(Lawrence V. Cipriani) writes: >>Is it legal to apply the & (address of) operator to an array >>element that is non-existent? >> for (p = a; p < &a[NTHINGS]; p++) /* 1 */ >>Will 1 be guaranteed to work in ANSI-C? > >Yes. If necessary, the compiler will put a one-byte (or word or >whatever) shim after the array in that array's address space, so >that &a[NTHINGS] will be meaningful. But, doesn't the draft (my copy is from November) also say that p+i (where p is a pointer) can only be dereferenced if it points to the same array as does p? Since &a[NTHINGS] translates to &(*(a+NTHINGS)) and a+NTHINGS does not point to the same array as does a, the dereference is undefined. This allows array bounds checking in ANSI C. Try for(p = a; p < a+NTHINGS; p++) /* 3 */