On this page
  1. volatile
  2. Availability
  3. Syntax & Overview
  4. Notes & Pitfalls
  5. Example

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

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