Type qualifier restrict

OK, not to sound like a complete newbie but I have searched the web a few times but still failed to properly understand the use of restrict.

It restricts some pointer aliasing (I don't think I still get that).

So, my only question is, What is the advantage of:
struct x *foo = ALLOC(struct x, 1);
over
struct x *restrict foo = ALLOC(struct x, 1); ?

I really don't see what difference it makes in it's usage. I would really appreciate if someone here can properly explain the proper use and advantages of restrict over normal declaration.
Last edited on
Apparently, it's only used for function declarations, not for regular variables like you're doing.
For example, void *memcpy(void *restrict dst, const void *restrict src, size_t n);. This tells the compiler "I promise that the buffers pointed to by dst and src as used by this function will not overlap". If the promise is broken, the behavior is undefined.
I assume it's there to allow the compiler to do some optimizations.
Topic archived. No new replies allowed.