Enums and immutables

Oleg B via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 18 05:22:38 PDT 2017


Hello. I found strange behavior while casting enum array and 
immutable array.

import std.stdio;

void main()
{
     enum arr = cast(ubyte[])[0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4];

     auto arr1 = cast(void[])arr;
     immutable arr2 = cast(immutable(void)[])arr;
     enum arr3 = cast(void[])arr;

     writeln(cast(ushort[])arr1); // [0, 256, 0, 512, 0, 768, 0, 
1024]
     writeln(cast(ushort[])arr2); // [0, 256, 0, 512, 0, 768, 0, 
1024]
     writeln(cast(ushort[])arr3); // [0, 0, 0, 1, 0, 0, 0, 2, 0, 
0, 0, 3, 0, 0, 0, 4]
}

I think it's related to representation of enums by compiler as 
#define.
It's right? It's behavior by design?


More information about the Digitalmars-d-learn mailing list