arrays (was Another silly question)

Chris Torek chris at mimsy.UUCP
Fri May 26 21:08:23 AEST 1989


In article <96 at elf115.uu.net> rec at elf115.uu.net (Roger Critchlow) writes:
>I think of C arrays as syntactic sugar for initialized pointers.
>Thus
>
>	char foo[] = "I am an anonymous char *";
>
>is an abbreviation for
>
>	register char *const foo = "I am an anonymous char *";

The only problem with this is that it is wrong.

Given the first declaration, sizeof(foo) is 25.  Given the second,
sizeof(foo) is typically something like 4.  This is only the most obvious
of many differences.

An array is an array, and a pointer is a pointer, and the twain meet
only in rvalue contexts, where an object of type `array N of T' is
converted to one of type `pointer to T' whose value is &array[0].
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list