Array literals

KennyTM~ kennytm at gmail.com
Sat Oct 18 08:31:09 PDT 2008


Michel Fortin wrote:
> On 2008-10-17 16:00:55 -0400, "Nick Sabalausky" <a at a.a> said:
> 
>> As long as we're talking about initializing jagged static arrays, I'd 
>> also
>> add one other slight change. The following should also compile (the 
>> current
>> D1 equivilent code complains. Not sure about D2):
>>
>> // The only change from the code above is
>> // swapping the order of "Hello" and "what"
>> import std.stdio: writefln;
>> void main() {
>>     char[static][static] a = ["what", "Hello"];
>>     writefln(a[1].length); // 5
>> }
>>
>> Might just be a bug, but currently (assuming the T[static] got 
>> implemented),
>> the above would fail to compile with an error complaining that it cannot
>> convert "Hello" from type char[5u] to type chat[4u]. Apperently,
>> "a[anything].length" is assumed to be "a[0].length" instead of
>> "max(a[0].length, a[1].length,...a[$-1].length)". So, currently, 
>> a[0].length
>> must be >= the longest of the rest of the strings. That's bitten me a few
>> times already.
> 
> For that to work, you'd also need implcit conversion from T[4] to T[5]. 
> How are your proposing to do that?
> 

Pad with T.init



More information about the Digitalmars-d mailing list