the restrict qualifier
/ ree-STRIKT /
Two pointers ALIAS when they may point at the same memory. When a function takes two pointers, the compiler usually has to assume they might overlap, which forces it to reload values it could otherwise have kept in a register — costing speed. The restrict qualifier, added in C99, is a PROMISE you make: 'for the life of this pointer, the object it points to is reached ONLY through this pointer (or pointers derived from it).' That promise lets the optimizer relax.
You write it as a qualifier on a pointer, for example void add(int *restrict dst, const int *restrict a, const int *restrict b). By marking dst, a, and b as restrict, you tell the compiler their regions do not overlap, so it may load each input once, compute freely, and store results without fear that writing through dst changed what a or b point to. Crucially, restrict is YOUR guarantee, not something the compiler checks: if the regions actually do overlap and you accessed the object through another pointer, the behavior is undefined.
It matters most in tight numeric loops, memory copies (note that memcpy promises non-overlap while memmove does not), and library hot paths, where it can unlock vectorization and remove redundant reloads. The danger to respect: a false restrict promise is undefined behavior — the optimizer is allowed to ASSUME no overlap and may produce code that silently computes the wrong answer if you lie, with no diagnostic at all.
void add(int *restrict dst, const int *restrict a, const int *restrict b, size_t n) { for (size_t i = 0; i < n; i++) dst[i] = a[i] + b[i]; } // caller must ensure dst, a, b name non-overlapping arrays
restrict lets the compiler assume the three arrays do not overlap, enabling reloads to be removed and the loop vectorized.
restrict is a promise the compiler does NOT verify; if the regions actually overlap, the result is undefined behavior — the optimizer may assume non-overlap and silently produce wrong output.