casting array literals doesn't work as stated in the docs

Trass3r un at known.com
Sun Jan 3 03:35:11 PST 2010


Am 03.01.2010, 12:20 Uhr, schrieb bearophile <bearophileHUGS at lycos.com>:
> It's not supposed to work, "dup" allocated memory with malloc, so it's  
> (currently) a run time thing (in future this may change).
>

So how to "create" an array expression at compile-time to enforce  
reinterpret_cast instead of conversion?


   // cast array literal
   const short[] ct = cast(short[]) [cast(byte)1, 1];
   writeln(ct);  // writes [1 1]

   // cast other array expression
   short[] rt = cast(short[]) [cast(byte)1, 1].dup;
   writeln(rt);  // writes [257]



More information about the Digitalmars-d mailing list