digitalmars.D.learn - how to set struct alignof?
- Andrew Fedoniouk (9/9) Mar 21 2005 As stated in D documetation (http://www.digitalmars.com/d/struct.html):
- Regan Heath (5/8) Mar 21 2005 See:
- Derek Parnell (17/29) Mar 21 2005 The 'align(x)' attribute is used to tell DMD how to align structures and
- Derek Parnell (23/51) Mar 21 2005 Ummmm... should this compile ok?
- Andrew Fedoniouk (1/1) Mar 21 2005 Thanks a lot, guys.
As stated in D documetation (http://www.digitalmars.com/d/struct.html): a.. [structure] "alignment can be explicitly specified" The question is : how? What notation I should use to define alignof for let's say struct A { ushort B; } Thanks.
Mar 21 2005
On Mon, 21 Mar 2005 16:25:33 -0800, Andrew Fedoniouk <news terrainformatica.com> wrote:As stated in D documetation (http://www.digitalmars.com/d/struct.html): a.. [structure] "alignment can be explicitly specified" The question is : how?See: http://www.digitalmars.com/d/attribute.html#align Regan
Mar 21 2005
On Tue, 22 Mar 2005 12:33:48 +1200, Regan Heath wrote:On Mon, 21 Mar 2005 16:25:33 -0800, Andrew Fedoniouk <news terrainformatica.com> wrote:The 'align(x)' attribute is used to tell DMD how to align structures and not the structure members. To align the members inside a struct you need to set the struct alignment to 1, and then provide explicit fillers for gaps in the RAM mapping. align(1) struct MyStruct { byte A; byte[3] filler1; byte B; byte filler2; short C; } -- Derek Melbourne, Australia 22/03/2005 11:38:37 AMAs stated in D documetation (http://www.digitalmars.com/d/struct.html): a.. [structure] "alignment can be explicitly specified" The question is : how?See: http://www.digitalmars.com/d/attribute.html#align Regan
Mar 21 2005
On Tue, 22 Mar 2005 11:42:11 +1100, Derek Parnell wrote:On Tue, 22 Mar 2005 12:33:48 +1200, Regan Heath wrote:Ummmm... should this compile ok? import std.stdio; align(1) struct MyStruct { byte A; byte[3] filler1; byte B; byte filler2; short C; } void main() { MyStruct s; writefln("%d %d %d", s.A.offsetof, s.B.offsetof, s.C.offsetof); } -- Derek Melbourne, Australia 22/03/2005 11:42:38 AMOn Mon, 21 Mar 2005 16:25:33 -0800, Andrew Fedoniouk <news terrainformatica.com> wrote:The 'align(x)' attribute is used to tell DMD how to align structures and not the structure members. To align the members inside a struct you need to set the struct alignment to 1, and then provide explicit fillers for gaps in the RAM mapping. align(1) struct MyStruct { byte A; byte[3] filler1; byte B; byte filler2; short C; }As stated in D documetation (http://www.digitalmars.com/d/struct.html): a.. [structure] "alignment can be explicitly specified" The question is : how?See: http://www.digitalmars.com/d/attribute.html#align Regan
Mar 21 2005