[Haskell-cafe] Specify array or list size?
Marcin 'Qrczak' Kowalczyk
qrczak at knm.org.pl
Sat May 7 15:28:32 EDT 2005
Antti-Juhani Kaijanaho <antti-juhani at kaijanaho.info> writes:
>> 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":
Ok, so in C terminology "type" is different from most statically typed
languages in this respect. The dimension is used together with the
type to determine static properties, and 6.7.5.2:4 says:
[#4] For two array types to be compatible, both shall have
compatible element types, and if both size specifiers are
present, and are integer constant expressions, then both
size specifiers shall have the same constant value. If the
two array types are used in a context which requires them to
be compatible, it is undefined behavior if the two size
specifiers evaluate to unequal values.
In C++ the size is considered a part of the type:
8.3.4 Arrays [dcl.array]
1 In a declaration T D where D has the form
D1 [constant-expressionopt]
and the type of the identifier in the declaration T D1 is "derived-
declarator-type-list T," then the type of the identifier of D is an
array type. T is called the array element type; this type shall not
be a reference type, the type void, a function type or an abstract
class type. If the constant-expression (_expr.const_) is present, it
shall be an integral constant expression and its value shall be
greater than zero. The constant expression specifies the bound of
(number of elements in) the array. If the value of the constant
expression is N, the array has N elements numbered 0 to N-1, and the
type of the identifier of D is "derived-declarator-type-list array of
N T."
In both languages lvalueness is also not considered a part of the type
but an alternative language presentation could use a wording where it is.
--
__("< Marcin Kowalczyk
\__/ qrczak at knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/
More information about the Haskell-Cafe
mailing list