expression
Target-specific atomic availability
Atomic capabilities depend on the target architecture and compilation configuration. Check target_has_atomic before selecting a width; a different target may require a different design. The sample reports a fixed message instead of assuming a pointer width. Expected stdout (not executed): target checked Common mistake: Assuming every target supports all integer atomic widths.
Formal Syntax & Structure
rust syntaxrust
#[cfg(target_has_atomic = "ptr")]Working Example
Example Snippetrust
fn main() { #[cfg(target_has_atomic = "ptr")] { let n = std::sync::atomic::AtomicUsize::new(1); assert_eq!(n.into_inner(), 1); } println!("target checked");}