r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • Sep 24 '26
About alignment, struct layout and the cache...
https://meetingcpp.com/blog/items/About-alignment--struct-layout-and-the-cache---.html
36
Upvotes
View all comments
Show parent comment
1
u/LB-- Professional+Hobbyist Sep 29 '26 edited Sep 29 '26
The ABI is only affected by the memory layout. The construct/destruct order only needs to be known by the constructors and destructors, which don't have to be defined inline. I can imagine a new type of declaration/definition combo, allowing you to either define the order inline in the class body, or to declare that it will be defined out-of-line, and must be defined before constructors/destructors need it. So for example you could add the forward declaration of custom order to the header, then define the full order in the source file above the constructors and destructors. No ABI breakage in that case. Alternatively, each constructor and destructor could declare its own preferred order, but that might be tricky for reasons beyond my consideration.