3 ms·
The point is that if you care about the resulting in-memory layout then you by definition know on what platform the code will run and what is the ABI. If you w
by dfox 4y ago
The point is that if you care about the resulting in-memory layout then you by definition know on what platform the code will run and what is the ABI.
If you want to produce same sequence of bytes regardless of underlying platform, then you have to do it by hand with uint8_t[] buffers and explicit shifts and masks. Casting pointer to struct to char* and writing it somewhere is inherently non-portable and this gas nothing to do with bitfields and nothing to do with things like __attributte__((packed)), although both of these things are useful when you want to do that and understand the (non-)portability implications.
- ncmncm 4y agoTotally missing the point. This not about exact bit placement, which is a whole other bag of worms.