Restrict is a big hammer. You can work around aliasing suspicions simply by imagining you are programming a load-store machine whereby local variables are registers. You have some algorithm that works with several different objects, such as structures and arrays. You can help the compiler (and the reader!) by writing code that isn't repeatedly dereferencing pointers, but which loads values into local variables.
Concrete example, doubly-linked list deletion, bad:
Here, the compiler doesn't know whether the assignment to victim->prev->next clobbers victim->next, which is evaluated again in the second line. If you write it like this, you eliminate that concern:
The assignments here do not interfere; the first line assigns to a "prev" structure member, and the next line doesn't access any such thing; it uses the "prev" local variable which isn't a structure member.
Caching in local variables is preferrable to using some C99 "restrict" voodoo that introduces undefined behavior.
In the case of the above linked list, where are you even going to stick "restrict"? There is only one incoming pointer, victim. Making that "restrict" doesn't help. You need it in the actual structure declaration on the next and prev pointers. Yuck, what?
Concrete example, doubly-linked list deletion, bad:
Here, the compiler doesn't know whether the assignment to victim->prev->next clobbers victim->next, which is evaluated again in the second line. If you write it like this, you eliminate that concern: The assignments here do not interfere; the first line assigns to a "prev" structure member, and the next line doesn't access any such thing; it uses the "prev" local variable which isn't a structure member.Caching in local variables is preferrable to using some C99 "restrict" voodoo that introduces undefined behavior.
In the case of the above linked list, where are you even going to stick "restrict"? There is only one incoming pointer, victim. Making that "restrict" doesn't help. You need it in the actual structure declaration on the next and prev pointers. Yuck, what?