When i pass TwoStruct { one: 1, two: 2 } to a C function that prints out the struct contents, it prints out 1, 2 as expected. But when I pass ThreeStruct { one: 1, two: 2, three: 3 } it prints out gibberish instead of the expected 1, 2, 3.
Why?
I have included a repo so you can run the code, more info in README
thank you it worked, i've done some further searching apparently C expects the entire ThreeStruct in stack, but rust normally optimises this by putting the first 16 byte of the struct in a register
The differences may vary on other targets -- even the one that appeared to work in your example might fail elsewhere. Using extern "C" makes sure to match whatever the target uses.