Path: utzoo!mnetor!uunet!husc6!hao!ames!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Address of Array Message-ID: <9775@mimsy.UUCP> Date: 14 Dec 87 23:02:33 GMT References: <126@citcom.UUCP> <2550034@hpisod2.HP.COM> <1854@haddock.ISC.COM> <1445@houdi.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 60 Summary: You are still confused >In article <9735@mimsy.UUCP> I wrote: >>... in the near future, one will be able to write the following: [an important line deleted here] >> p = g() ? &z[0] : &z[2]; In article <1445@houdi.UUCP> marty1@houdi.UUCP (M.BRILLIANT) writes: >I can write > char *a, b[14]; > a = &b[3]; >without getting any complaints from the compiler. Yes, but you deleted my declaration for z: int z[4][10]; >Writing &b without an index in brackets still draws a warning from the >compiler that & before an array is ignored. Exactly: and it WILL NOT once your compiler is compliant with the ANSI X3J11 standard. >The storage location where the array begins is known to the compiler >by the name b, *WITH WHAT TYPE?* Answer *THAT* and you may see what &b will mean. >but since that address is not accessible as data at run time, &b has >no meaning. NO! It has no meaning *NOW*; it *WILL* in the *FUTURE*! AAAAAAARGH! (There, I feel better now.) Given the declaration `char b[14]', the value of &b will be the same as the value of &b[10] with one important difference: The TYPE of &b[0] is `char *'; the TYPE of &b will be `char (*)[14]'. [Aside: the exact representation of the two values may differ, depending on, e.g., type tag bits. This is irrelevant to the future language definition.] This is the key: C is a typed language. B is not; B has `words'. C is; C has `pointer to char' and `pointer to pointer to char' and `pointer to int' and . . . and each type is different and mutually incompatible. Two expressions with the same value but different types are different. The very quote above, `The storage location where the array begins...' shows that you are thinking of C as an untyped language. This is wrong. Every value has a type. Given the declaration `int a[N};', the difference between `&a[0]' and `&a' is the type of the expression. Expressions arepairs. Leaving out either piece of the pair gives you an improper expression: something that is not C. Remember that: pairs. The difference between &a[0] and &a is (will be) in the `type' half. (Now *that* has *got* to be clear....) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris