2 ms·
> the default ABI settings should get you completely compatible layouts here That's not true! You must not assume that the alignment always equals the size of
by spacechild1 3y ago
> the default ABI settings should get you completely compatible layouts here
That's not true! You must not assume that the alignment always equals the size of a type. For example, the SysV i386 ABI uses 32-bit alignment for 64-bit types (double, int64_t). The Microsoft x86 ABI, however, uses 64-bit alignment, as do all 64-bit ABIs (See https://stackoverflow.com/a/11110283 https://stackoverflow.com/a/11110283.)
If you want to share structs directly between different machines, you should use appropriate struct packing directives - unless you really know what you are doing.
- LegionMammal978 3y agoWhat's worse, MSVC's 32-bit x86 ABI reports an 8-byte alignment requirement (via __alignof) for 64-bit integer types, and its struct layout algorithm uses that alignment to determine padding, but those integers and structs are only aligned to 4 bytes when allocated on the stack! This has caused issues with Rust code trying to link with MSVC code [0], since Rust's standard library documentation asserts that properly aligned pointers have addresses that are always a multiple of the alignment used for struct layout. [0] https://github.com/rust-lang/rust/issues/112480 https://github.com/rust-lang/rust/issues/112480