Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!uakari.primate.wisc.edu!ames!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: "array" vs. "&array" ? Message-ID: <21516@mimsy.umd.edu> Date: 28 Dec 89 19:25:47 GMT References: <1989Dec22.013757.3086@sj.ate.slb.com> <571@mwtech.UUCP> <1989Dec28.100415.17825@eng.umd.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 46 Disclaimer: I do not know this guy :-) >In article <21419@mimsy.umd.edu> I wrote: >> &arr >>produces either a warning (Classic C), or a value of type `pointer >>to array SIZE of basetype' (New C). >>> p = &a; >>Unfortunately, when handed to an Old C compiler, you get: >>>warning: & before array or function: ignored >>>warning: illegal pointer combination, op = In article <1989Dec28.100415.17825@eng.umd.edu> dskim@eng.umd.edu (Daeshik Kim) writes: > If I define "char a[10];" and use " &a" (e.g. address of array a) > , isn't this undefined? No. Reread <21419@mimsy.umd.edu>, this time without preconceived notions: > To my understanding, "&a" is the address of the address of the base > of 10 bytes mem. The only place I can think of, is where the compiler > keeps the info. of allocated memory( activation record ). No. `a' (as defined above) is the name of an array, therefore &a is Some C books (including K&R-1) would lead you to believe that anywhere `a' occurs in C code it means `the address of the first of ten characters'. This is false: `a' means `the variable a'. In *value contexts* (NOT everywhere), it is *converted to* (does not start out as) a value that has a pointer type (namely `char *'). The operand of unary `&', however, is NOT in a value context. (If it were, you could ask for `&(a + b)'.) It is in an object context, and objects in object contexts stay objects: arrays do not degenerate into pointers. The `&' thus sees the object (array 10 of char) and not the address (pointer to a[0]) that, e.g., `char *p = a;' sees. Again, in Old (or Classic or K&R-1) C, the unary `&' does not accept arrays or functions, but in New (or ANSI or K&R-2) C, it does accept arrays. The obvious thing for `address of ' to become is `', and this is what happens (in NEW C ONLY). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris