문제

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).

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top