int pthread_create(pthread_t *restrict thread,
const pthread_attr_t *restrict attr,
void *(*start_routine)(void*), void *restrict arg);
I would like to know what the meaning of restrict is?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s something introduced in C99 which lets the compiler know that the pointer passed in there isn’t pointing to the same place as any other pointers in the arguments. If you give this hint to the compiler, it can do some more aggressive optimizations without breaking code.
As an example, consider this function:
Obviously, it adds two numbers from pointers. We can use it like this if we want:
Obviously, it will output 8; it’s adding 4 to itself. However, if we add
restricttoaddlike so:Then the previous
mainis now invalid; it’s passing&numberas both arguments. You may, however, pass in two pointers pointing to different places.