Path: utzoo!mnetor!uunet!husc6!rutgers!umn-d-ub!umn-cs!randy From: randy@umn-cs.cs.umn.edu (Randy Orrison) Newsgroups: comp.lang.c Subject: Re: Address of Array Message-ID: <3179@umn-cs.cs.umn.edu> Date: 12 Dec 87 16:39:56 GMT References: <126@citcom.UUCP> <2550034@hpisod2.HP.COM> <1854@haddock.ISC.COM> <532@ndsuvax.UUCP> <2020@ttrdc.UUCP> <555@ndsuvax.UUCP> <1949@haddock.ISC.COM> <5308@zen.berkeley.edu> Reply-To: randy@umn-cs.UUCP (Randy Orrison) Organization: UofM Math Department Lines: 44 In article <5308@zen.berkeley.edu> sarge@scam.berkeley.edu (Steven Brian McKechnie Sargent) writes: >In article <1949@haddock.ISC.COM> karl@haddock.ima.isc.com (Karl Heuer) writes: >>address of an entire array entity (which differs from the address of the first >>element in exactly the same way that the address of a structure differs from >>the address of its first member), and this is exactly the problem that X3J11 >>has fixed by legalizing "&a". > >Um, no. Given an object, s, of type "struct s", &s + 1 does NOT refer to the >second element in the struct. Address arithmetic just doesn't "make sense" >with structures the same way that it does with arrays. Um, yes. Given an object, s, of type "struct snarf" or "array [n] of gonk", &s + 1 is a pointer to the next object of the same type in memory. Note that in the case of arrays, &s + 1 is VERY different from the much more common &s[0] + 1, which is the next element of the array. (There is nothing that corresponds to this for structures, execpt &s[0]->firstelement). In BOTH cases &s + 1 does NOT refer to the second element. Nothing in that expression talks about elements, and there's no way for the compiler to know where to find the second element (whether s is a struct or array). Now - the reason that you are confused: The C that Karl and I are talking about is not the same C as you are used to. This is ANSI C, not K&R, not pcc, not H&R. Now, I have a question: this all makes sense to me if you have a variable of type pointer to array { char (*s)[10] } but how does this apply when your variable is an array itself { char s[10] }? I suppose it makes sense... is this right: With declarations (on the stack, contiguous in memory...) char s[16]; char t[16]; Is it true that: *(&s + 1) == t (assuming array comparisons)? Arg. Well, they may not be first class, but they're moving up in the world... -randy-- Randy Orrison, University of Minnesota School of Mathematics | UUCP: {ihnp4, seismo!rutgers, sun}!umn-cs!randy | (hello?) ARPA: randy@ux.acss.umn.edu BITNET: randy@umnacca | "I need a unit to sample and hold, but not the angry one: a new design."