Вопрос

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