If I got the C99 restrict
keyword right, qualifying a pointer with it is a promise made that the data it references won't be modified behind the compiler's back through aliasing.
By contrast, the way I understand the const
qualifier is as compiler-enforced documentation that a given object won't be modified behind the back of a human being writing code. The compiler might get a hint as a side effect, but as a programmer I don't really care.
In a similar way, would it be appropriate to consider a restrict
qualifier in a function prototype as a requirement that the user ensures exclusive access ("avoid aliasing", or maybe something stronger) for the duration of the call? Should it be used as "documentation"?
Also, is there something to understand in the fact that restrict
qualifies a pointer rather than the data it points to (as const
does) ?
EDIT: I originally believed that restrict
could have implications with threaded code, but this seems wrong so I remove references to threads from the question to avoid confusing readers.