4 ms·
There can be subtle bugs, especially if you have code which has to adhere to a strict on-disk or on-network format. I recently committed a change to FreeBSD's
by drewg123 7y ago
There can be subtle bugs, especially if you have code which has to adhere to a strict on-disk or on-network format.
I recently committed a change to FreeBSD's kernel (written in C) which I'd tested on amd64 and x86. Much to my surprise, when I did the cross-build for all platforms, I had a compile-time assert fail on 32-bit arm because the size of a struct was too large. It turns out that 32-bit arm (at least on FreeBSD) naturally aligns 8 byte data types to 8 byte boundaries, whereas x86 packs them and allows them to straddle the 8 byte boundary. This left a 4-byte hole in my struct, and caused it to be 4 byte too large.
These are the sorts of things that bite you when moving from x86/x86_64 to a risc platform, even when its the same endian.
- saagarjha 7y agoIf you care about the packing of your struct, then you should probably be using compiler-specific packing attributes.