by omoikane · 2y ago · 0 comments
https://learn.microsoft.com/en-us/cpp/preprocessor/pack?view...
GCC and Clang also support this pragma:
https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Structure-Layo...
https://clang.llvm.org/docs/UsersManual.html#microsoft-exten...
Rust can take it a bit further. In rust, fields must be aligned to a multiple of their size, and structs/tuples must be aligned to a multiple of their largest element. This combination makes it very easy to handle memory offsets, or reusing the same representation in a way that reduces memory usage (these are called niches)[1].
This is why dynamic linking is a bit more complex in rust. Alternatively you can offer a C bridge via `extern "c"`. C will act as a bridge between rust and different languages, and at that stage you need to take care of ordering and padding.