Type Qualifiers
Overview
The qualifiers const, volatile, and restrict are used to convert unqualified versions of types to their qualified versions.
Starting in C23, an array and its element type are always considered to be identically qualified. Other derived types (such as pointers) are not qualified by the qualifiers of the type from which it is derived. For example, a pointer to a const type does not mean the pointer itself is const.
const
The const type qualifier indicates that an object is read-only. This may be used by the compiler for optimizations.
restrict
The restrict type qualifier indicates an object referred to by a pointer is only accessible through said pointer. In other words, a restrict-qualified pointer prohibits aliasing.
volatile
The volatile type qualifier indicates that the corresponding object must be:
- Reloaded from memory every time it is accessed, and
- Stored to memory each time it is modified.
In other words, they are protected (or potentially inhibited) from optimization.