sizeof and multi-dimensional arrays

Chris Torek chris at mimsy.umd.edu
Wed Jan 9 17:16:10 AEST 1991


In article <1991Jan8.234328.5075 at sol.UVic.CA> gmclaren at sirius.UVic.CA
(Gavin  Mclaren) writes:
>>char x[2][3];
>What's to be confused about?  x is a pointer to a two dimensional array,

No, x is an <object, array 2 of array 3 of char>.  There is one thing to
be confused about already.  (To get a pointer to x, write `&x'.  This
gives a <value, pointer to array 2 of array 3 of char, &x>.)

>Is this perhaps an example of how some are confused by the pointer-array 
>equivalence _theory_ in the C language?

Yes.  There is no real `pointer-array equivalence'; there is, however, a
(one, single) rule that makes the use of arrays and pointers use the same
syntax.  That rule is:

    In a value context, an object of type `array N of T' (where N is
    some integral constant and T is a suitable type, including another
    `array Nprime of Tprime') is converted to a value of type `pointer
    to T' which points to the first element of the array, i.e., the one
    with subscript 0.

This conversion occurs only in value contexts.  (There is a completely
separate rule that applies to formal parameter declarations.)

>My best advice is to muddle through the FAQ, one more time....

The FAQ answers are not intended as full tutorials (there is not enough
space, among other things).

For much more detail about this, see my previous postings.
-- 
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