What const Really Is
const is a compile-time promise.
Hardware enforces real protection.
What const Really Is (C Language Level)
At the C language level, const is only a type qualifier.
It tells the compiler:
The compiler enforces this rule at compile time, before any code runs.
Key point:
It is a promise enforced by the compiler, not by hardware
It tells the compiler:
“This object must not be modified through this identifier.”
That’s it.The compiler enforces this rule at compile time, before any code runs.
Key point:
- const does not say where the data is stored
- const does not say the data is physically immutable
It is a promise enforced by the compiler, not by hardware
Symbol Table & Object File Reality
During compilation,
In the object file:
But — and this matters —
const symbols are typically marked as:- Read-only
- Non-writable
In the object file:
- The symbol metadata reflects immutability
- The compiler assumes the value never changes
But — and this matters —
- The compiler does not decide whether this lives in Flash or RAM.
The Linker: Where const Actually Goes
The linker uses:
Common sections:
On many MCUs:
But that is policy, not law.
Change the linker script, and this changes instantly
- Section attributes
- Linker script rules
- Target memory map
Common sections:
- .rodata → read-only data
- .data → initialized RAM data
- .bss → zero-initialized RAM
On many MCUs:
.rodata → Flash
.data → RAM
So by convention, const data often ends up in Flash..data → RAM
But that is policy, not law.
Change the linker script, and this changes instantly
5. const Does NOT Mean Flash
This is the most dangerous myth in embedded C.
Reality:
Example:
This could be:
const does not imply physical immutability.
Reality:
- const means read-only from C's perspective
- Flash placement is a linker decision
- Hardware may still modify the memory
Example:
const uint32_t calibration_value;This could be:
- In Flash
- In RAM
- In external memory
- In shared memory updated by DMA
const does not imply physical immutability.