C restrict
关键字/限定符是否可以通过多个级别的指针间接传递?
例如,给定以下片段:
struct Bar {
int b;
};
struct Foo
{
struct Bar* bar;
};
int examineFoos(struct Foo* restrict foo1, struct Foo* restrict foo2)
{
foo1->bar->b = 1;
return foo2->bar->b;
}
int main(void)
{
struct Bar bar = { 0 };
struct Foo foo1 = { .bar = &bar };
struct Foo foo2 = { .bar = &bar };
int val = examineFoos(&foo1, &foo2);
return val;
}
这是否会调用未定义的行为并可以调用val == 0
,因为它在访问bar
时违反了restrict
,或者这是有效代码,并且我们总是得到val == 1
,因为restrict
没有通过bar
指针传递应用?