Open colindr opened 5 years ago
In C all structs need to have a different address. It is unexpected that the size is four in windows though...
I was expecting it to not have an _address field because that is what is generated on Linux. The "Expected Results" in the issue is the output that I get when I run bindgen on Linux with the same input.
Ah, I didn't notice that... That's weird indeed, probably MSVC has a different ABI than gcc for empty structs and we're choking on it.
It is worth mentioning that the C standard makes empty structs UB.
(C11, 6.7.2.1 Structure and union specifiers p8) "If the struct-declaration-list does not contain any named members, either directly or via an anonymous structure or anonymous union, the behavior is undefined."
MSVC seems to reject this outright, GCC makes it size zero. In C++, however, empty structs are valid and always 1 byte. (MSVC, GCC)
Not sure what clang says on Windows. Might mimick GCC's behaviour. It'd probably be best to reject empty C structs altogether
rustc also has problems with repr(C)
and MSVC: rust-lang/rust#81996
Input C Header
Bindgen Invocation
This is specifically for windows. I've installed LLVM according to the documentation, and I'm setting my LIBCLANG_PATH like so (in powershell):
Then I invoke bindgen like so:
Actual Results
Expected Results
I expected it to generate an empty rust struct, like so:
From this issue I understand that the _address field is supposed to be added for C++ structs, but this is a C struct. Also, the tests that are generated are incorrect, the u8 _address field is 1usize not 4usize.
I've tested this on linux and it's not a problem there.
Here are the debugging logs: