Is there a way to tell D to rearrange struct members or to not rearrange class members?
WraithGlade
wraithglade at protonmail.com
Fri Jun 27 11:23:56 UTC 2025
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.
So, the question here is, is there a way to make the D compiler
change that behavior per specific `class` and `struct` type
definitions or at least across the whole compilation?
I looked in the `pragma` section in the D library documentation
but didn't find it and didn't find it elsewhere either (e.g. it
wasn't in the `man` page for DMD).
Does anyone know if such memory arrangement control is possible
currently?
It isn't a major problem at all (easy to work around, such as by
embedding a `struct` in a class for `class`s, or manually
reordering `struct` members for `struct`s), but I was just
curious.
Thanks for reading, as always!
More information about the Digitalmars-d-learn
mailing list