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

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


Am 03.01.2010, 12:33 Uhr, schrieb bearophile <bearophileHUGS at lycos.com>:

>
> // alternative 1:
> enum RGBA[] data1 = [{0x00, 0x10, 0x20, 0x30}, {0x40, 0x50, 0x60, 0x70}];
> // alternative 2:
> enum RGBA[] data2 = [RGBA(0x00, 0x10, 0x20, 0x30), RGBA(0x40, 0x50,  
> 0x60, 0x70)];
>
>

Alternative 1: I heard struct literals could be removed.
Alternative 2:
1) it's cumbersome, especially if you got a huge array
2) if you somehow fundamentally change the struct for whatever reason, you  
probably have to reassign everything.

I currently use the old casting hack:
auto PALETTE = (cast(RGBA*) cast(ubyte[]) [0xFF,...]) [0 .. 256];


I just ask if it's possible to do it in a nicer way, i.e. either
1) the current behavior needs to be changed so casting to arrays of  
structs always does a reinterpret_cast or
2) there must be some way to turn an array literal into an array  
expression at compile-time (i.e. without using .dup) to force  
reinterpretation.



More information about the Digitalmars-d mailing list