-
Notifications
You must be signed in to change notification settings - Fork 748
Different types on Windows? #1361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is invalid, I think. MSVC generates a different underlying type for enums by default, see: That program, which for reference is: #include <type_traits>
#define __UI_ENUM(s) typedef unsigned int s; enum
extern "C" {
__UI_ENUM(uiAlign) {
uiAlignFill,
uiAlignStart,
uiAlignEnd,
};
}
int main() {
static_assert(
std::is_same<std::underlying_type<decltype(uiAlignFill)>::type, unsigned>::value,
"Huh");
} Only fails to compile on MSVC. So bindgen is right in this case, even if it ends up not quite mattering given the values never go out of range (I hope :)). If it was C++ you could use Let me know if I can help more to get the bindings working and in a sane state, binding to libui is really cool! |
Thanks for reproducing that! MSVC is... wrong in this case, I think? We do explicitly ask for an unsigned enum. In any case, using Rust-ified enums should be fine here. I'll let you know if I have any more issues. |
I don't think so because I think the enum is anonymous and |
Oh, I see! Thanks, I misunderstood what that declaration was doing. |
It appears as if bindgen chooses i32 always for Windows, but varies for Mac and Linux. Relevant links: - https://users.rust-lang.org/t/bindgen-and-enum-types/34370 - rust-lang/rust-bindgen#1361 However, this behavior isn't in line with the C standard, which states: > The identifiers in an enumerator list are declared as constants that have type int and may appear wherever such are permitted. To remedy this for all platforms, enums are now default type i32.
It appears as if bindgen chooses i32 always for Windows, but varies for Mac and Linux. Relevant links: - https://users.rust-lang.org/t/bindgen-and-enum-types/34370 - rust-lang/rust-bindgen#1361 However, this behavior isn't in line with the C standard, which states: "The identifiers in an enumerator list are declared as constants that have type int and may appear wherever such are permitted." To remedy this for all platforms, enums are now default type i32.
…ants This is a fix for: #29 The existing code assumed that the Wolfram LibraryLink constants would have the same size and signedness on all platforms. This assumption was not correct on Windows targeting MSVC, where constants that would be u32 on other platforms would be i32. See also: * rust-lang/rust-bindgen#1244 * rust-lang/rust-bindgen#1361
…ants (#41) This is a fix for: #29 The existing code assumed that the Wolfram LibraryLink constants would have the same size and signedness on all platforms. This assumption was not correct on Windows targeting MSVC, where constants that would be u32 on other platforms would be i32. See also: * rust-lang/rust-bindgen#1244 * rust-lang/rust-bindgen#1361
On Windows, anonymous enums are translated to i32. On Linux and macOS, they're translated to u32. This fixes: #51 See also: rust-lang/rust-bindgen#1361
On Windows, anonymous enums are translated to i32. On Linux and macOS, they're translated to u32. This fixes: #51 See also: rust-lang/rust-bindgen#1361
The reason for this is that MSVC uses signed enum types by default. Cf. rust-lang/rust-bindgen#1361 (comment)
Input C/C++ Header
Bindgen Invocation
The Issue
I use these enums in Rust code, for instance, here:
On Linux, this code works. On Windows, it does not:
Check out more details, if needed, at LeoTindall/libui-rs#29
The text was updated successfully, but these errors were encountered: