Created
January 25, 2019 03:47
-
-
Save mohno007/a5d8ba3f0ffdd33ad967a86d145d5ea6 to your computer and use it in GitHub Desktop.
Rust i64 + (i32 as i64) = i64 + i64(with sign extension) = i64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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