main()1void main() 2 { 3 align(1) 4 struct X1 { ubyte b; int n; } 5 static assert(X1.sizeof == 8); 6 static assert(X1.b.offsetof == 0); 7 static assert(X1.n.offsetof == 4); 8 //X1 x1; 9 //assert(cast(void*)&x1.b == cast(void*)&x1 + 0); 10 //assert(cast(void*)&x1.n == cast(void*)&x1 + 1); 11 12 struct Y1 { ubyte b; int n; } 13 static assert(Y1.sizeof == 8); 14 static assert(Y1.b.offsetof == 0); 15 static assert(Y1.n.offsetof == 4); 16 //Y1 y1; 17 //assert(cast(void*)&y1.b == cast(void*)&y1 + 0); 18 //assert(cast(void*)&y1.n == cast(void*)&y1 + 4); 19 20 int local; 21 22 align(1) 23 struct X2 { ubyte b; int n; int f(){ return local; } } 24 static assert(X2.sizeof == 8 + (void*).sizeof); 25 static assert(X2.b.offsetof == 0); 26 static assert(X2.n.offsetof == 4); 27 //X2 x2; 28 //assert(cast(void*)&x2.b == cast(void*)&x2 + 0); 29 //assert(cast(void*)&x2.n == cast(void*)&x2 + 1); 30 31 struct Y2 { ubyte b; int n; int f(){ return local; } } 32 static assert(Y2.sizeof == 8 + (void*).sizeof); 33 static assert(Y2.b.offsetof == 0); 34 static assert(Y2.n.offsetof == 4); 35 //Y2 y2; 36 //assert(cast(void*)&y2.b == cast(void*)&y2 + 0); 37 //assert(cast(void*)&y2.n == cast(void*)&y2 + 4); 38 } 39