"array" vs. "&array" ?

Chris Torek chris at mimsy.umd.edu
Wed Jan 10 19:05:56 AEST 1990


>>   float arrf[3] = {1.2,2.3,3.4};
>>   arrf;            /*evaluates to pointer to float according to K&R*/

[note that this is because of a special case: `arrf' is an <object,
array N=3 of T=float, arrf> where a value is needed.]

In article <CHUCKP.90Jan9132735 at halley.ncr-fc.FtCollins.NCR.com>
chuckp at ncr-fc.FtCollins.NCR.com (Chuck Phillips) writes:
>When declaring/defining arrf, space is allocated for a pointer to the array
>_in the symbol table_, _not_ in the actual object code.

This is bogus.  The C language is not necessarily compiled, and even
if it is, the language itself does not claim anything about a `symbol
table'.  If a compiler emits correct code purely by divine guidance and
has no memory at all, it can still be a C compiler.

Again, `float *p; p = arrf;' puts `arrf' in value context, so a C
compiler is obliged to generate whatever code it takes to store the
address of the first (0'th) element of the array in the object `p'.
This address is stored in whatever representation is used for the
type `float *'.

In New (ANSI) C, `float (*q)[3]; q = &arrf;' has `arrf' in an object
context, not a value context; the `&' applies, and a C compiler is
obliged to generate whatever code it takes to store the address of
the entire array in the object `q'.  This address is stored in whatever
representation is used for the type `float (*)[3]'.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list