align(n) not working as expected
Robert Jacques
sandford at jhu.edu
Mon Dec 27 23:41:24 PST 2010
On Tue, 28 Dec 2010 00:32:37 -0700, %u <wfunction at hotmail.com> wrote:
> Hi,
>
> I'm not sure if I'm doing something wrong, but it seems like struct
> alignment
> isn't really working. (I just found out that I'm not supposed to post
> this on
> the digitalmars.D.bugs newsgroup, so I'm posting it here.)
>
> When I execute this code:
>
> struct Temp
> {
> ubyte x;
> align(16) ubyte y;
> }
> auto o = Temp();
> std.stdio.writefln("Address of aligned fields: %#x, %#x",
> cast(size_t)&o.x,
> cast(size_t)&o.y);
>
> I get these addresses:
> 0x18fd00, 0x18fd01
> the second of which is not aligned on a 16-byte boundary.
>
>
> Am I doing something wrong, or is this a bug?
>
> Thank you!
As per the docs, align behaves in the manner of the companion C++ compile.
DMC only defines align(1) and align(4), so they're the only two that work.
So this isn't a bug per say, but more than one of us has asked for
align(8)/align(16) support. (or at least a compile time warning). But
there's several technical/performance issues with maintaining alignment
different from the underlying OS. I'd also recommend D.learn for questions
like these.
More information about the Digitalmars-d
mailing list