3 ms·
Rust reorders struct layout as it wishes unless you opt-in to a C-like layout, so you only pay for it when you need it.
by epage 5y ago
Rust reorders struct layout as it wishes unless you opt-in to a C-like layout, so you only pay for it when you need it.
- alkonaut 5y agoYes, that's how I thought it worked in most languages (that have structs, and allow C-interop). You leave it open for the compiler to do anything/nothing unless you do e.g. repr(C) (In rust) or [StructLayout(LayoutKind.Explicit)] or similar (C#). I wouldn't want this to be explicit in the spec but nor would I manage without having the back door. In languages that don't have "structs" at all, it's obviously not as necessary because you'll be forced to jump through hoops anyway (JNI, for example).