Error with associative array initializer

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Jul 3 04:01:46 PDT 2007


Pontus wrote:
>> Make sure the type of the first expression is a dynamic array. "ab"[] or
>> cast(char[])"ab" would work.
> 
> I see that it works, but is it not a bit weird?
> 
> The type declarations is char[][int], the first part(char[]) looks like
>  a dynamic array to me. Why would the compiler assume it is char[2] just
> because the first element of the intializer looks like it?

It probably doesn't even look at the type of the declaration again until 
it has processed the initializer expression.

I'm actually a bit surprised that assigning a char[3][int] literal to a 
char[][int] works at all. The compiler probably has some special 
handling for those kinds of cases when it compares the types of the 
declaration and that of the initializer expression.
I guess given that fact it wouldn't be too unreasonable to expect the 
original code to work as well. It would certainly be nice if it would 
just do the Right Thing(TM).


More information about the Digitalmars-d-learn mailing list