Last active
August 29, 2015 14:28
-
-
Save michaelfairley/8265ca0ca3a2fbc80fb1 to your computer and use it in GitHub Desktop.
This file contains 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
use std::mem; | |
use std::ptr; | |
fn spooky(_data: &[f32; 3]) { | |
// This function does nothing. Calling it should have no effect on the program. | |
} | |
pub fn main() { | |
let data1 = [1.0, 2.0, 3.0]; | |
let data2 = [1.0, 2.0, 3.0]; | |
spooky(&data2); | |
unsafe { | |
let bytes1: [u8; 12] = ptr::read(mem::transmute(&data1)); | |
let bytes2: [u8; 12] = ptr::read(mem::transmute(&data2)); | |
println!("{}", bytes1 == bytes2); // Prints "false"; prints "true" if line 12 is commented out. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment