2 ms·
Having manual/explicit struct layout obviously allows solving this, but the usual reason languages (at any level) have them is because it’s a nightmare to do C-
by alkonaut 5y ago
Having manual/explicit struct layout obviously allows solving this, but the usual reason languages (at any level) have them is because it’s a nightmare to do C-Style interop without it. What’s the alternative here?
- epage 5y agoRust 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).