Skip to content

Instantly share code, notes, and snippets.

@michaelfairley
Last active August 29, 2015 14:28
Show Gist options
  • Save michaelfairley/8265ca0ca3a2fbc80fb1 to your computer and use it in GitHub Desktop.
Save michaelfairley/8265ca0ca3a2fbc80fb1 to your computer and use it in GitHub Desktop.
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