Path: utzoo!dciem!nrcaer!cognos!jimp From: jimp@cognos.uucp (Jim Patterson) Newsgroups: comp.lang.c Subject: Re: Is &a[NTHINGS] legal Message-ID: <2979@cognos.UUCP> Date: 11 May 88 13:16:25 GMT Article-I.D.: cognos.2979 Posted: Wed May 11 09:16:25 1988 References: <12074@tut.cis.ohio-state.edu> <1086@gazette.bcm.tmc.edu> <52339@sun.uucp> Reply-To: jimp@cognos.UUCP (Jim Patterson) Organization: Cognos Inc., Ottawa, Canada Lines: 34 In article <52339@sun.uucp> limes@sun.UUCP (Greg Limes) writes: >In article <1086@gazette.bcm.tmc.edu> biff@eyeball.ophth.bcm.tmc.edu.UUCP (Brad Daniels) writes: >> >>Whether or not the above is legal, I think it should probably be written as: >> >> for (p = a; p < (a+NTHINGS); p++) >> >>Or am I missing something obvious? > >What if (a+NTHINGS) wraps around the address space in such a way that >(a+NTHINGS) < a? The ANSI C draft explicitly allows for the syntax shown above (where a is declared "a[NTHINGS]". This is found in section 3.3.6 "Additive Operators" of the draft. The last sentence reads: "However, if P points to the last member of an array object, the expression (P+1) - P has the value 1, even though P+1 does not point to a member of the array object". (ANSI Doc X3J11/88-002 page 48). This is further clarified in the Rationale document. However, the intention is that such expressions should work as expected. In practice, the effect is that generally at least one addressable byte needs to follow any declared array such that its address follows that of the last array element. So, according to the ANSI committee, &a[NTHINGS] IS legal. -- Jim Patterson Cognos Incorporated UUCP:decvax!utzoo!dciem!nrcaer!cognos!jimp P.O. BOX 9707 PHONE:(613)738-1440 3755 Riverside Drive Ottawa, Ont K1G 3Z4