IT lexicon › Programming › restrict

restrict

Programming På svenska → Updated: 2026-11-06

The C99 keyword in which the programmer swears a pointer is the only way to its memory, letting the compiler optimise as if it were Fortran.

Fortran forbids overlapping arguments, which is why its compilers could vectorise loops that C compilers dared not touch. C99 answered in 1999 with the restrict type qualifier: for as long as the pointer lives, the object it points to is reached no other way. The compiler may then keep values in registers across stores and reorder loads as it pleases.

The standard library uses it to separate memcpy, whose buffers must not overlap, from memmove, which copes. Break the promise and you get undefined behaviour, with no warning. C++ never adopted the keyword, though every major compiler offers __restrict. Rust gives the same guarantee for free on every &mut, which turned into LLVM's toughest test of the optimisation.

← Back to the lexicon