On this page
volatile
Prev: restrict | Up: builtins | Next: _Atomic
Rel: Memory Layout & ABI, stdatomic.h
Ref: cppreference — volatile
Tags: #public #prog #c #builtins #tier/specialized
Availability
Built-in (Type Qualifier) — requires no #include header.
Syntax & Overview
volatile T reg;
Prevents the compiler from optimizing away or caching reads/writes to an object whose value can change outside normal program flow.
Notes & Pitfalls
- For memory-mapped I/O (MMIO) and
sig_atomic_tsignal flags ONLY:volatileis NOT a substitute for<stdatomic.h>or mutexes in multi-threaded code.
Example
#include <signal.h>
static volatile sig_atomic_t stop_requested = 0;
static void on_sig(int sig) { (void)sig; stop_requested = 1; }
Linked from
Related notes
- tuts/c/builtins/_Atomic Linked here; links to this page; shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/restrict Linked here; links to this page; shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins Linked here; links to this page; shared tags: #builtins, #c, #prog
- tuts/c/compilation_and_internals/memory_layout_and_abi Linked here; shared tags: #c, #prog
- tuts/c/stdlib/stdatomic Linked here; shared tags: #c, #prog
- tuts/c/builtins/__FILE__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__func__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__LINE__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__STDC_VERSION__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/_Alignof shared tags: #builtins, #c, #prog, #tier