(no title)
bengl3rt | 1 year ago
Does Rust fundamentally guarantee that if you make a struct, its fields will lay out in memory in the order that you defined them? Can it be used to interact with APIs (really ABIs) who expect a C struct (or pointer to one)?
I think my main frustration with stuff like Go and Swift in this case is that their structs are not binary-compatible with C structs in this way because they rearrange things to be better aligned/packed/whatever.
pitterpatter|1 year ago
https://doc.rust-lang.org/reference/type-layout.html#the-c-r...
Hemospectrum|1 year ago
You have to specify this behavior with #[repr(C)]. Otherwise, the compiler will rearrange fields to try to optimize packing and alignment.
mirashii|1 year ago
https://doc.rust-lang.org/reference/type-layout.html
https://github.com/rust-lang/compiler-team/issues/457
the8472|1 year ago
[0] https://github.com/bootreer/vroom/blob/37bd8a22f5e0550b2cbc9... [1] https://doc.rust-lang.org/reference/type-layout.html#the-ali...
thegeekpirate|1 year ago
https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/fie...
Zanfa|1 year ago
If you need binary-compatibility with C structs in Swift, you can define them in a bridging header.
nXqd|1 year ago
unknown|1 year ago
[deleted]