Skip to content

Instantly share code, notes, and snippets.

@ya-mouse
Created January 15, 2014 21:08
Show Gist options
  • Save ya-mouse/8444726 to your computer and use it in GitHub Desktop.
Save ya-mouse/8444726 to your computer and use it in GitHub Desktop.
Wrong type casting leads to wrong value
use std::io::println;
fn main() {
let m : [u8, ..1] = [ 0u8 ];
println(format!("{}", ((m[0] >> 8) | 0) as u16));
println(format!("{}", ((m[0] >> 8) | m[0]) as u16));
assert!((((m[0] >> 8) | 0) as u16) == 0);
assert!((((m[0] >> 8) | m[0]) as u16) == 255);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment