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. For example, suppose we want to represent the positions of pieces on a chessboard which has the usual 8 files (columns), but more (or fewer) ranks (rows) than the usual 8. This declaration could hold a pointer to a two-dimensional array that can hold that data. Each element of the array holds one row.
struct chesspiece *funnyboard[][8];
Since it is just a pointer to the start of an array, its type can be incomplete, but it must state how big each array element is—the number of elements in each row.
Next: Limitations of C Arrays, Previous: Array Type Designators, Up: Arrays [Contents][Index]