s1 * __restrict
means that this is the only pointer to a specific s1
, so there are no aliases for this type. This does not mean that there will be no aliases for other types of pointers, such as void*
, int*
or char*
.
Using char*
especially difficult for the compiler, because char*
specifically allowed to use other types of bytes. ( char
also means byte and can be used to access other types of main memory).
If the compiler cannot prove that your task will never, ever change what is indicated, it will have to reload the pointer each time. For example, how can he say that void* field1
not pointing to itself?
And wouldn’t it be something like this work without all the casts?
int* p = my_s1.field1; p[1] = 0; p[2] = 1; p[3] = 2; p[4] = 3;
Assuming int
has 4 bytes and that field1
actually points to an array of them.
source share