Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: "array" vs. "&array" ? Message-ID: <15638@haddock.ima.isc.com> Date: 12 Jan 90 19:46:07 GMT References: <24521@gryphon.COM> <21764@mimsy.umd.edu> <5248@buengc.BU.EDU> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 26 In article <5248@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: >Usually when you ask for the pointer to an array you get a >pointer to the first element of the array. No, you get a pointer to the entire array (in ANSI C) or an error (in K&R C), except in those pre-ANSI compilers that chose, as an extension, to make the misinterpretation you describe (usually accompanied by a warning). >E.g.: > type_t *aptr, a[MAXINDEX+1]; > aptr = &a; I don't know of any compiler that will accept that line without a diagnostic. To reiterate the ANSI convention (the only one worth mentioning, since the other behavior is really just correcting a "probably typo" for &a[0]): type_t (*aptr)[SIZE], a[SIZE]; aptr = &a; if ( *aptr == a ) puts( "Will always print this." ); Note that "*aptr" and "a" are both array objects, and hence in the rvalue context of the compare *each* will be converted to a pointer: if ( &(*aptr)[0] == &a[0] ) Karl W. Z. Heuer (karl@haddock.isc.com or ima!haddock!karl), The Walking Lint