partial initialization of fixed size ("static") arrays

kdevel kdevel at vogtner.de
Sat Aug 14 09:40:54 UTC 2021


Today I stumbled across three issues with partial initialization 
of "static" arrays:

~~~i1.d
void main ()
{
    char [7] b = [ 1: 'x' ]; // okay
    char [7] a = [ 0: 'x' ]; // i1.d(4): Error: mismatched array 
lengths, 7 and 1
}
~~~

~~~i2.d
import std.stdio;

void main ()
{
    char [7] c7 = [ 1: 'x' ];
    writeln (cast (ubyte [7]) c7); // [255, 120, 255, 255, 255, 
255, 255] okay
    char [7] d7 = "x";
    writeln (cast (ubyte [7]) d7); // [120, 0, 0, 0, 0, 0, 0] 
would have expected
                                   // [120, 255, 255, 255, 255, 
255, 255]
}
~~~

~~~i3.d
// i3.d
void main ()
{
    string s = "x";
    static assert (is (typeof (s) == typeof ("x")));
    assert (s == "x");
    char [7] c7 = s; // throws RangeError
}

$ dmd -g i3
$ ./i3
core.exception.RangeError at i3.d(7): Range violation
----------------
??:? _d_arrayboundsp [...]
i3.d:7 _Dmain [...]
~~~

Shall I file them to bugzilla?


More information about the Digitalmars-d-learn mailing list