Question

I have the following structure:

typedef struct{
    int data[LENGTH];
}Data;

and use it like so:

Data* dt=CALLOC(...)

int foo(Data* restrict d){
    for(...)
        d[i]->data[j];
    //do stuff with data[]
}

My question is: Does removing strict aliasing from d also affect its members or do I need to use restrict on them separately? In other words, does restrict imply that all pointers contained in a struct get the same treatment?

Edit: By level of aliasing I mean, if a pointer to a struct gets restricted, would any other pointers contained in it be restricted as well (as is the case with my example).

Was it helpful?

Solution

restrict only applies to the annotated pointer itself (or pointers generated from it, such as by pointer arithmetic), not any of the values retrieved through that pointer.

I'm not sure what 'levels of strict aliasing' is supposed to mean, but restrict is a more powerful promise than that of strict aliasing. Strict aliasing allows pointers of compatible type to alias: restrict is a promise that there is no aliasing at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top