Skip to content

Instantly share code, notes, and snippets.

@mohno007
Created January 25, 2019 03:47
Show Gist options
  • Save mohno007/a5d8ba3f0ffdd33ad967a86d145d5ea6 to your computer and use it in GitHub Desktop.
Save mohno007/a5d8ba3f0ffdd33ad967a86d145d5ea6 to your computer and use it in GitHub Desktop.
Rust i64 + (i32 as i64) = i64 + i64(with sign extension) = i64
sh-3.2$ rustc test.rs
warning: literal out of range for i32
--> test.rs:2:40
|
2 | println!("{:x}", 0x100000000_i64 + 0xcafebabe_i32 as i64);
| ^^^^^^^^^^^^^^ help: consider using `u32` instead: `0xcafebabe_u32`
|
= note: #[warn(overflowing_literals)] on by default
= note: the literal `0xcafebabe_i32` (decimal `3405691582`) does not fit into an `i32` and will become `-889275714i32`
sh-3.2$ ./test
cafebabe
fn main() {
println!("{:x}", 0x100000000_i64 + 0xcafebabe_i32 as i64);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment