Summary: semantics of casting arrays need to be reworked
           Product: D
           Version: 2.000
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid, spec
          Severity: major
          Priority: P2
            Blocks: 2494

--- Comment #0 from Trass3r <> 2010-03-12 13:09:28 PST ---
It needs to be clarified when a reinterpret_cast is done and when the elements
are converted to the new type depending on whether it is an array literal,
another array expression, an array of structs, classes or interfaces AND
whether it is a constant array or not.
A sane and consistent solution is required.

The only information at all is hidden deep inside the huge expressions

What is the rationale for this inconsistency?

(Also, is this information correct? For example I thought array literals are
dynamic arrays now ("The AssignExpressions form the elements of a static
Additionally: "The type of the first element is taken to be the type of all the
elements" ->

We already had several discussions about it here:
followed by

For example, I want a byte array to be saved in the executable file which is
reinterpreted in the code as RGB structs:

RGB[256] PALETTE = cast(RGB[256]) [
    0x00, 0x00, 0x00, 0xE3, 0x53, 0x00,
    0xCF, 0x4B, 0x07, 0xBF, 0x43, 0x0F, ...

doesn't work cause of "non-constant expression"

RGB[256] PALETTE = (cast(RGB[]) [
    0x00, 0x00, 0x00, 0xE3, 0x53, 0x00,
    0xCF, 0x4B, 0x07, 0xBF, 0x43, 0x0F, ...
]) (0 .. 256);

compiles, but yields empty structs (cause it tries to cast each element to a
struct instance if I'm not mistaken)

RGB[] PALETTE = (cast(RGB*) cast(ubyte[]) [...])[0..256];

makes it work, but of course it's a bit hacky.

Also see:
and my answer:

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to