Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Is &a[NTHINGS] legal Message-ID: <7806@brl-smoke.ARPA> Date: 30 Apr 88 16:06:59 GMT References: <12074@tut.cis.ohio-state.edu> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 20 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? Given: > sometype a[NTHINGS], *p; >Should: > for (p = a; p < &a[NTHINGS]; p++) /* 1 */ >be written as: > for (p = a; p <= &a[NTHINGS-1]; p++) /* 2 */ > ... >Will 1 be guaranteed to work in ANSI-C? Yes, it is. This kind of code is quite pervasive, and if you consider that NTHINGS might have been defined as 0 it is impossible to avoid (in fact in that situation your case 2 is invalid). Every object must have at least one addressable cell beyond it, but not necessarily in front of it. The reason the latter is not required is that &a[-1] may be MANY bytes in front of allocated storage if the array element is large, but &a[NTHINGS] will be just one byte past the valid array locations.