Closed
Description
Some architectures have small integer types such as AVR, which has 16-bit int
.
For preprocessor constants, bindgen emits the constant in Rust as a constant with type libc::c_int
. If c_int
is i16
, large constants can overflow, causing compiler warnings.
This is a pretty obscure bug because it only appears on esoteric platforms with a small int type. At some point bindgen could be modified so that it detects constant overflow and promotes to the next bigger integer type.
Input C/C++ Header
#define NTP_OFFSET 3155673600
#define UNIX_OFFSET 946684800
Actual Results
warning: literal out of range for u16
--> src/bindings.rs:162:48
|
162 | pub const UNIX_OFFSET: ::rust_ctypes::c_uint = 946684800;
| ^^^^^^^^^
warning: literal out of range for u16
--> src/bindings.rs:163:47
|
163 | pub const NTP_OFFSET: ::rust_ctypes::c_uint = 3155673600;
| ^^^^^^^^^^
warning: literal out of range for u16
--> src/bindings.rs:864:53
|
864 | pub const __AVR_LIBC_DATE_: ::rust_ctypes::c_uint = 20150209;
Expected Results
Bindgen maps the preprocessor defines to Rust constants which have types large enough to fit the integer literal.