3 ms·
Lost but not forgotten. IDK, most these rules are very trivial and fairly simple to automate. Pretty much boils down to declare the smallest fields first, with
by valarauca1 9y ago
Lost but not forgotten.
IDK, most these rules are very trivial and fairly simple to automate. Pretty much boils down to declare the smallest fields first, with a handful of exceptions based on the modulus of size.
Ultimately I like Rust’s approach. Without including ‘[repr(C)]/[repr(packed)]’ the compiler is free to layout the structure in the most efficient way for the target platform. And accessing fields with different compiler’s code is UB. You get the speed up, while keeping backwards compatibility.
Sadly C/C++ are shackled to this archaic system. Also I believe Go, Nim, and Swift are as well (this is speculation).
- loeg 9y agoIt's not even lost. Any C code that cares about performance will eventually look into how structures are laid out in cache lines.
- valarauca1 9y agoIt is a requirement for code heavily using atomics as false shares and destroy performance.
- deleted 9y ago[deleted]
- millstone 9y agoIf switching compilers results in UB, how is that keeping backwards compatibility?
- valarauca1 9y ago`[repr(C)]` maintains compatibility with C-ABI, therefore keeping backwards compatibility with C, C++, Rust, etc. As the C ABI, and C structure layout rules are standardized across platforms.