// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. #![feature(untagged_unions)] use std::mem::{size_of, size_of_val, align_of, align_of_val}; struct S { a: u16, b: [u8; 3], } #[repr(packed)] struct Sp { a: u16, b: [u8; 3], } union U { a: u16, b: [u8; 3], } #[repr(packed)] union Up { a: u16, b: [u8; 3], } const CS: S = S { a: 0, b: [0, 0, 0] }; const CSP: Sp = Sp { a: 0, b: [0, 0, 0] }; const CU: U = U { b: [0, 0, 0] }; const CUP: Up = Up { b: [0, 0, 0] }; fn main() { let s = S { a: 0, b: [0, 0, 0] }; assert_eq!(size_of::(), 6); assert_eq!(size_of_val(&s), 6); assert_eq!(size_of_val(&CS), 6); assert_eq!(align_of::(), 2); assert_eq!(align_of_val(&s), 2); assert_eq!(align_of_val(&CS), 2); let sp = Sp { a: 0, b: [0, 0, 0] }; assert_eq!(size_of::(), 5); assert_eq!(size_of_val(&sp), 5); assert_eq!(size_of_val(&CSP), 5); assert_eq!(align_of::(), 1); assert_eq!(align_of_val(&sp), 1); assert_eq!(align_of_val(&CSP), 1); let u = U { b: [0, 0, 0] }; assert_eq!(size_of::(), 4); assert_eq!(size_of_val(&u), 4); assert_eq!(size_of_val(&CU), 4); assert_eq!(align_of::(), 2); assert_eq!(align_of_val(&u), 2); assert_eq!(align_of_val(&CU), 2); let up = Up { b: [0, 0, 0] }; assert_eq!(size_of::(), 3); assert_eq!(size_of_val(&up), 3); assert_eq!(size_of_val(&CUP), 3); assert_eq!(align_of::(), 1); assert_eq!(align_of_val(&up), 1); assert_eq!(align_of_val(&CUP), 1); }