Path: utzoo!utgpu!water!watmath!clyde!att!att-ih!pacbell!ames!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Is &a[NTHINGS] legal Message-ID: <11305@mimsy.UUCP> Date: 2 May 88 04:09:07 GMT References: <12074@tut.cis.ohio-state.edu> <11289@mimsy.UUCP> <5997@utcsri.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 31 >>In article <12074@tut.cis.ohio-state.edu> lvc@tut.cis.ohio-state.edu >>(Lawrence V. Cipriani) writes: >>> for (p = a; p < &a[NTHINGS]; p++) /* legal? */ >In article <11289@mimsy.UUCP> I answered: >>Yes. In article <5997@utcsri.UUCP> norvell@utcsri.UUCP (Theodore Stevens Norvell) writes: >But, doesn't the draft ... also say that p+i (where p is a pointer) >can only be dereferenced if it points to the same array as does p? Yes. >Since &a[NTHINGS] translates to &(*(a+NTHINGS)) No, not the way you mean this. `Is equivalent to', not `evaluates as': the indirection does not occur. Only the address computation occurs; the value at a+NTHINGS is not examined. >... the dereference is undefined. True. It also does not occur. >This allows array bounds checking in ANSI C. Bounds checking is still possible, but &a[NTHINGS] must be allowed, while both a[NTHINGS] and &a[NTHINGS+1] should be rejected. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris