Next: Limitations of C Arrays, Previous: Array Type Designators, Up: Arrays [Contents][Index]
An array is equivalent, for most purposes, to a pointer to its zeroth
element. When that is true, the length of the array is irrelevant.
The length needs to be known only for allocating space for the array, or
for sizeof
and typeof
(see Auto Type). Thus, in some
contexts C allows
extern
declaration says how to refer to a variable allocated
elsewhere. It does not need to allocate space for the variable,
so if it is an array, you can omit the length. For example,
extern int foo[];
int func (int foo[])
These declarations are examples of incomplete array types, types
that are not fully specified. The incompleteness makes no difference
for accessing elements of the array, but it matters for some other
things. For instance, sizeof
is not allowed on an incomplete
type.
With multidimensional arrays, only the first dimension can be omitted:
extern struct chesspiece *funnyboard foo[][8];
In other words, the code doesn’t have to say how many rows there are, but it must state how big each row is.