3 ms·
Compilers (for C and C++) typically provide mechanisms to control padding and other layout requirements as necessary to make this work. It's not that unusual i
by azornathogron 3y ago
Compilers (for C and C++) typically provide mechanisms to control padding and other layout requirements as necessary to make this work.
It's not that unusual in C and C++ code to define a struct that has a specific and well-defined memory layout. It's kosher, as long as you accept that you're working with a specific set of real compilers and use the appropriate #pragmas or other controls as needed to avoid undefined behaviour.
- bjourne 3y agoYep, but then you force the compiler to choose a specific struct-layout which may be suboptimal if, for example, coding for simd. You also can't control the values of the struct padding bytes which may cause very interesting bugs.