Is &a[NTHINGS] legal

Lawrence V. Cipriani lvc at tut.cis.ohio-state.edu
Sat Apr 30 22:14:56 AEST 1988


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 */
		...

I like 1 better than 2 since there are fewer characters to
type and I find it quicker and easier to comprehend.  The
dpANS says & only applies to objects that are not bit fields
or have the register qualifier.  In this example, one could
argue that a[NTHINGS] doesn't even exist so that & should be
invalid on it.  Will 1 be guaranteed to work in ANSI-C?
Thanks,

-- 
Larry Cipriani, AT&T Network Systems and Ohio State University
Domain: lvc at tut.cis.ohio-state.edu
Path: ...!cbosgd!osu-cis!tut.cis.ohio-state.edu!lvc (weird but right)



More information about the Comp.lang.c mailing list