Created
April 14, 2021 19:27
-
-
Save Ciantic/89b9f84c97b5dfe21dbe342200d3bd4d to your computer and use it in GitHub Desktop.
Tuple layout
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
#[repr(C)] | |
struct Foo(f32, f32, f32); | |
fn main() { | |
let a = [Foo(1.0,2.0,3.0), Foo(4.0,5.0,6.0)]; | |
let b = [1.0f32,2.0,3.0,4.0,5.0,6.0]; | |
let c = [(1.0f32,2.0f32,3.0f32), (4.0f32,5.0f32,6.0f32)]; | |
let amem = unsafe { std::slice::from_raw_parts((&a as *const _) as *const u8, std::mem::size_of_val(&a) )}; | |
let bmem = unsafe { std::slice::from_raw_parts((&b as *const _) as *const u8, std::mem::size_of_val(&b) )}; | |
let cmem = unsafe { std::slice::from_raw_parts((&c as *const _) as *const u8, std::mem::size_of_val(&c) )}; | |
// These are all equal | |
println!("{:?}", amem); | |
println!("{:?}", bmem); | |
println!("{:?}", cmem); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment