So my understanding is that the C99 standard mandates that pointers to different types should not be aliased (i.e. pointed to the same memory). The restrict
keyword assures the compiler that two certain variables (of the same type?) are not located in the same memory slot.
Therefore, is it true, that the following function would not profit form the restrict
keyword?
void sphere_intersect(float* t, const sphere* s, const ray* r);
But, a function like this would:
void vector_add(vector* v, const vector* u);
A function like
could benefit from adding restrict if the types
sphere
and/orray
contain anyfloat
fields. Absentrestrict
, the compiler must assume thatt
might alias with anyfloat
field in the objects pointed at bys
orr
. So any write to*t
might modify such a field meaning that the compiler could not hold the value of said field in a register for later reuse, but would instead have to reload it.