Document somewhere that enums can be either c_int or c_uint
Input C/C++ Header
enum TestEnum {
FOO,
BAR
};
Bindgen Invocation
$ bindgen input.h
Actual Results
On Windows:
/* automatically generated by rust-bindgen 0.56.0 */
pub const TestEnum_FOO: TestEnum = 0;
pub const TestEnum_BAR: TestEnum = 1;
pub type TestEnum = ::std::os::raw::c_int;
On Ubuntu:
/* automatically generated by rust-bindgen 0.56.0 */
pub const TestEnum_FOO: TestEnum = 0;
pub const TestEnum_BAR: TestEnum = 1;
pub type TestEnum = ::std::os::raw::c_uint;
Expected Results
This should be documented somewhere. All I found is this comment: https://github.com/rust-lang/rust-bindgen/issues/1096#issuecomment-365797349
Bindgen uses whatever enum type comes from clang, so if it's a u32, clang is picking a u32 type for it.
A more precise definition is that bindgen will use std::underlying_type_t<Enum>. But yeah, adding docs for this would be great.
can we have an option to just always make a c_int on all platforms, because the signedness only matters to Rust and C doesn't care?
Resurrecting this thread because we just stumbled upon the same issue. In our case we have something like the following:
pub const my_enum_VALUE_0: my_enum = 0;
pub const my_enum_VALUE_1: my_enum = 1;
...
pub type my_enum = u32;
I believe the problem here is that the enumeration constants should always be int, as specified by the C standard, rather than my_enum. The type of my_enum itself can be whatever clang spits out. In any case, it would be nice to have an option to control this as @Lokathor suggested.
Just stumbled over this as well. For reference: https://stackoverflow.com/a/366033/1717115
Basically the C standard specifies that an enum value always needs to be representable by int, although the compiler can choose different types for the actual representation.