expression

Understand initialized data and zeroed storage

A typical bare-metal runtime initializes RAM before calling application Rust code. Initialized static data may have initial bytes stored in flash; zero-initialized storage usually occupies RAM without equivalent stored data bytes. This array copy is a host model only. Actual startup and section names depend on the target and linker script; do not implement reset handlers from this model. Expected host stdout (not executed): data: [3, 5], bss: [0, 0, 0] Common mistake: Assuming RAM already contains the required initial values immediately after reset.

Formal Syntax & Structure

rust syntaxrust
startup copies .data and initializes .bss (target-specific)

Working Example

Example Snippetrust
fn main() {    let flash_initial = [3u8, 5];    let mut data_ram = [0; 2];    let mut bss_ram = [9u8; 3];    data_ram.copy_from_slice(&flash_initial);    bss_ram.fill(0);    println!("data: {data_ram:?}, bss: {bss_ram:?}");}
Rust Reference