[Haskell-cafe] Specify array or list size?

Thomas Davie tom.davie at gmail.com
Sat May 7 14:49:17 EDT 2005


> No, it introduces a variable of type "array of 50 ints", which can be
> converted to "pointer to int".
>
> It matters when you make a pointer of such arrays, an array of such
> arrays, or sizeof such array. In C++ the size can be matched by
> template parameter, and you can have separate overloadings for
> separate array sizes.
>

I'm not familiar with your C++ example (not being familiar with C++),  
but I think that it's a bit of a stretch of the imagination to say  
that C "introduces a variable of type "array of 50 ints"", the fact  
that this is now an array of 50 integers is never checked at any  
point in the compilation or run, and I'm not sure it can be even if  
K&R had wanted to.  If I'm thinking straight then *any* array  
definition merely gets re-written to a memory allocation of the  
relevant amount of ram, and beyond this point it is forever of type  
"pointer to <array content type>".

As an example:

int bobsArray[5];
bobsArray[6] = 23;

is not badly typed – it is merely a badly broken program.

Bob


More information about the Haskell-Cafe mailing list