Is there a way to tell D to rearrange struct members or to not rearrange class members?
Dejan Lekic
dejan.lekic at gmail.com
Fri Jun 27 11:54:17 UTC 2025
On Friday, 27 June 2025 at 11:23:56 UTC, WraithGlade wrote:
> I've read both of the available printed D books in their
> entirety (Ali's and Andrei's) and I noticed Andrei's book
> (circa ~2010) mentions that the D compiler rearranges the
> members of `class` objects to be more optimal by reducing
> alignment-induced padding whereas it leaves the
> alignment-induced padding of `struct` objects exactly the same
> as implied and required by the order in which you've written
> the members of the struct.
Lots of things changed since Andrei's book.
I am guessing what you meant is - is there a way to control
struct alignment, right?
The answer is yes - D has a nice way of controlling the
alignment. - Here is a relevant section that explains it in fine
details: https://dlang.org/spec/attribute.html#align
More information about the Digitalmars-d-learn
mailing list