[Haskell-cafe] Specify array or list size?

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Sat May 7 15:49:19 EDT 2005


David Roundy <droundy at abridgegame.org> writes:

> No, int (*p)[50] is a multidimensional array, one of the most useless
> concepts in C, and is equivalent to int p[50][] (or is it p[][50]...
> I always get my matrix subscripts messed up).

No, it's not equivalent to either. Array type are not the same as
pointer type.

(Except that in function parameters an array type really means a pointer.)

int p[50][] is an error because array element type must be a complete type,
and an array without a dimension is an incomplete type.

int p[][50] declares p as an array with unknown size, of arrays of size 50.
Such declaration makes sense:
1. as a declaration of an array defined elsewhere (usually with "extern");
   it must have a size specified in some place;
2. with an initializer in braces, whose size determines the array size;
3. as function parameter, where it means a pointer.

int (*p)[50] declares p as a pointer to an array of size 50. Such declaration
can be used anywhere without restrictions - this is a complete type.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


More information about the Haskell-Cafe mailing list