Let’s say that I have a buffer of chars and I want to avoid using memcpy, and access to it through an int* variable:
char buffer[100];
strcpy(buffer,"Hello");
int* __restrict ptr=(int*)buffer;
*ptr= 97;
printf("%s",buffer);
Now this of course prints “a”.
Am I allowed to do this without encountering an undefined behaviour?
Well, only on little endian machines.
And strict aliasing would have nothing do with your example as one of the type is
charandcharmay alias anything if the goal ofrestrictwasn’t to increase the number of cases where the compiler may assume that there is no alias, i.e. even when typing information wouldn’t prevent it.And obviously if you want information about
__restrictwhich is in the implementation domain, you should specify the implementation.