Search code examples
ddmd

How to fix this union size/alignment requirement under DMD 2.060


A D2 source code containing the following snippet can be compiled under DMD 2.059

union Prefix {
  char[9] data;
  align(1) struct { uint fileno; uint lineno; char delim; };
}
static assert(Prefix.sizeof == 9);

and unfortunately fails under DMD 2.060 (Prefix.sizeof becomes equal to 12).

How can it be fixed?


Solution

  • This seems to do what you want:

    align(1) union Prefix
    {
        ubyte[9] data;
    
        struct
        {
            uint fileno;
            uint lineno;
            char delim;
        }
    }
    
    static assert(Prefix.sizeof == 9);