[Haskell-cafe] Specify array or list size?

David Roundy droundy at abridgegame.org
Sat May 7 15:31:05 EDT 2005


On Sat, May 07, 2005 at 08:20:15PM +0100, Thomas Davie wrote:
> On May 7, 2005, at 8:07 PM, Marcin 'Qrczak' Kowalczyk wrote:
> >The size is taken into account when such array type is an element of
> >another array, and by sizeof.
> >
> >int (*p)[50]; /* p may legally point only to arrays of 50 ints each */
> >++p; /* p is assumed to point into an array, and is moved by one
> >        element, i.e. by 50 ints */
>
> I'm not sure what you're trying to prove by saying that... There is  
> still no type information that says that the contents of p are an  
> array of 50 elements... I can still attempt to access element 51 and  
> get a runtime memory error.  The type of p is still int**, not  
> "pointer to array of 50 ints"

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).

In a multi-dimensional array, all the dimensions but the first (or last?)
are fixed in size.  Unfortunately, these are fixed at compile time, so
there's no way to write a function that can act upon multidimensional
arrays of arbitrary size.  So we get the joy of writing terms like m[i+n*j]
to deal with matrices...
-- 
David Roundy
http://www.darcs.net


More information about the Haskell-Cafe mailing list