Thread overview | ||||||
---|---|---|---|---|---|---|
|
June 03, 2010 I still don't understand the align attribute | ||||
---|---|---|---|---|
| ||||
http://digitalmars.com/d/2.0/attribute.html#align "align by itself sets it to the default, which matches the default member alignment of the companion C compiler." OK! "align(Integer): Integer specifies the alignment which matches the behavior of the companion C compiler when non-default alignments are used" I don't really understand that sentence. "struct S { align(4) byte a; // placed at offset 0 align(4) byte b; // placed at offset 1 }" So those align(4)s are completely useless since the default alignment is chosen anyways? "align (1) struct S { byte a; // placed at offset 0 byte[3] filler1; byte b; // placed at offset 4 byte[3] filler2; }" This is just as I would expect but this leaves no chance to specify alignment for individual members, does it? |
June 03, 2010 Re: I still don't understand the align attribute | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | Trass3r: > So those align(4)s are completely useless since the default alignment is chosen anyways? On 64 bit CPUs/systems the alignment can be 8, so if you ask for 4 you get 4 instead of 8. > This is just as I would expect but this leaves no chance to specify alignment for individual members, does it? You can put the alignment to single members. I suggest you to print the .alignof attribute of all your members in your experiments, so you can answer to your own questions in a quick way. Bye, bearophile |
June 03, 2010 Re: I still don't understand the align attribute | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | > I suggest you to print the .alignof attribute of all your members in your experiments, so you can answer to your own questions in a quick way.
I meant the .offsetof attribute, sorry.
|
June 17, 2010 Re: I still don't understand the align attribute | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | Trass3r wrote: > http://digitalmars.com/d/2.0/attribute.html#align > > "align by itself sets it to the default, which matches the default member alignment of the companion C compiler." > OK! > > "align(Integer): Integer specifies the alignment which matches the behavior of the companion C compiler when non-default alignments are used" > I don't really understand that sentence. <snip> Basically, it means that the member is aligned on n-byte boundaries in whatever way the companion C compiler does if instructed to. However, there's no statement I can find of what's supposed to happen if the companion C compiler doesn't support alignment control at the level where it is used. http://d.puremagic.com/issues/show_bug.cgi?id=3183 (marked as fixed, but it seems it isn't really) http://www.digitalmars.com/d/archives/digitalmars/D/Spec_of_align_attribute_is_a_mess_88129.html Stewart. |
Copyright © 1999-2021 by the D Language Foundation