In C there is restrict
keyword which tells the compiler that there is no aliasing between pointer arguments of a function, allowing it this way to perform some optimizations which otherwise will not be allowed. For example:
void add(int* restrict ptrA,
int* restrict ptrB,
int* restrict val)
{
*ptrA += *val;
*ptrB += *val;
}
Now the instructions in function body can be executed in parallel because there is not aliasing between val
and some of the ptr
arguments. In C++ there is no restrict
keyword.
- What are exact rules for dealing of pointer aliasing in C++ defined by the standard?
- What are popular compilers extensions which provide semantic similar to
restrict
in C? For example for MSVC, g++, clang++ and Intel C++ compiler. - Is there any plans
restrict
keyword to be standardized in the future C++ standards?