expression
C representation and field order
C representation places struct fields in declaration order using target alignment rules. This is useful for interoperable data structures, but does not choose an endian format or guarantee a portable file format. Expected stdout (not executed): 0 1 2 Common mistake: Assuming repr(C) recursively changes the representation of nested Rust types.
Formal Syntax & Structure
rust syntaxrust
#[repr(C)]Working Example
Example Snippetrust
#![deny(unsafe_op_in_unsafe_fn)]fn main() { use std::mem::offset_of; #[repr(C)] struct Header { kind: u8, flags: u8, bytes: [u8; 3] } println!("{} {} {}", offset_of!(Header, kind), offset_of!(Header, flags), offset_of!(Header, bytes));}