[Haskell-cafe] Specify array or list size?

Antti-Juhani Kaijanaho antti-juhani at kaijanaho.info
Sat May 7 15:03:11 EDT 2005


On 20050507T203246+0200, Marcin 'Qrczak' Kowalczyk wrote:
> > In C and C++, the declaration int n[50]; introduces an array variable
> > with size 50 having the type "array of int".  The size is *not* part of
> > the type.
> 
> No, it introduces a variable of type "array of 50 ints", which can be
> converted to "pointer to int".

ISO 9899:1999 (C99) section 6.7.5.2:3 says that its type is "array of
int", not "array of 50 ints":

  If, in the declaration ``T D1'', D1 has one of the forms:
         D[ type-qualifier-listopt assignment-expressionopt ]
         D[ static type-qualifier-listopt assignment-expression ]
         D[ type-qualifier-list static assignment-expression ]
         D[ type-qualifier-listopt * ]
  and the type specified for ident in the declaration ``T D'' is ``
  derived-declarator-type-list T '', then the type specified for ident
  is ``derived-declarator-type-list array of T ''.121) (See 6.7.5.3 for
  the meaning of the optional type qualifiers and the keyword static.)

  121) When several ``array of'' specifications are adjacent, a
  multidimensional array is declared.

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

For C, in all those cases, the array size is a property of the variable,
not of the type. 
-- 
Antti-Juhani Kaijanaho                  http://antti-juhani.kaijanaho.info/

		Blogi - http://kaijanaho.info/antti-juhani/blog/
                 Toys - http://www.cc.jyu.fi/yhd/toys/


More information about the Haskell-Cafe mailing list