Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



Yep, 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: