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?

有帮助吗?

解决方案

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);

其他提示

Placing the align(1) before the union keyword is enough to make the assert pass, because the data inside it is naturally aligned without gaps. Otherwise, you'd need to add align(1): before the union's / struct's fields.

Probably a bug. Or some obscure logic, because naming a struct returns aligning back.

EDIT: Filed a bug: http://d.puremagic.com/issues/show_bug.cgi?id=8566

EDIT: Walter explained me my mistake there :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top