문제

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