I'm having quite hard time making proper usage of restrict
keyword in C. I wrote this function to in-place reverse a string:
void my_strrev(char *restrict str, const size_t len) {
char *restrict strr = str + len - 1;
char temp;
while (str < strr) {
temp = *str;
*str++ = *strr;
*strr-- = temp;
}
}
Here, although both str
and strr
are pointing to same array, I'm using those pointers to access individual characters, and they never point to same characters. Hence I think this is a proper use of restrict
. Also I got expected output when I run this program with few sample inputs. But I'm unsure of my usage of restrict
. So, please correct me if I'm doing wrong.