4 ms·
Pad - yes, typically. Reorg - seldom.
by virgilp 7y ago
Pad - yes, typically. Reorg - seldom.
- klodolph 7y agoReorg is prohibited by C standard.
- virgilp 7y agoI know, it wasn't obvious to me that elteto talked exclusively about C/C++. AFAIK few -if any- compilers/VMs take it upon themselves to reorder struct members (even outside C/C++ world).
- leni536 7y agoEven though struct member reordering is prohibited, the order of std::tuple elements are not fixed by the standard. There could be an stdlib implementation that used this fact to reorder tuple members optimally. AFAIK there are PoC 3rd party implementations for such tuples.
- saagarjha 7y agoBoth Swift and Rust have an unspecified structure ordering by default, which almost always boils down to "the compiler will lay them out in the order specified, except if you leave enough padding to fit a member, in which case it'll reorder the elements for you".
- gpderetta 7y agoIt is complicated. Because of the as-if rule, a compiler can do anything it wants as long as a conforming program can't tell the difference. So for example if a compiler can prove that a program doesn't compare fiel addresses, doesn't cast pointer to a struct to its first member, etc it can reorder as it pleases. Turns out it is very hard to prove, often requires whole program optimization and the gains are questionable, so it is seldom done. Both clang and gcc had such an optimization pass in the past but it got dropped.