Bug 8566 – Inconsistency in aligning named and anonymous structs

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-08-20T05:47:00Z
Last change time
2012-08-20T15:23:26Z
Assigned to
nobody
Creator
public

Comments

Comment #0 by public — 2012-08-20T05:47:51Z
Code sample: ================================================= import std.stdio; union Anonymous { char[9] buffer; align(1) struct { align(1): int a; int b; char c; } } union Named { char[9] buffer; align(1) struct Name { align(1): int a; int b; char c; } } void main() { writeln(Named.sizeof); writeln(Anonymous.sizeof); } ================================================= Output: 9 12
Comment #1 by bugzilla — 2012-08-20T15:23:26Z
An unnamed struct/union allocates storage for its members. A named one does not, it just defines a type. Hence the size difference.