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

bearophile bearophileHUGS at lycos.com
Sun Jan 3 05:00:31 PST 2010


Trass3r:
> Alternative 1: I heard struct literals could be removed.

I haven't heard that. They are recently changed a little, but you already know that from another thread.


> Alternative 2:
> 1) it's cumbersome, especially if you got a huge array

But it's clean & readable, and more flexible because later you can add a static opCall that does what you want. You can use a Python script or an IDE to generate the D code.


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

This looks OK for a 20 lines long script for your personal usage, but I refuse it in production code.
The code must be first of all tidy, and it must use a clean semantics, unless you have already profiled the code and found out that a spot is not fast enough for the program users. Unless otherwise required, you must program as your stereotypical granny drives, or later the code will bite your rear :-)

Bye,
bearophile



More information about the Digitalmars-d mailing list