Use of __restrict__ in g++
Andrew Haley
aph@redhat.com
Tue Mar 31 09:28:00 GMT 2009
[ Redirected to gcc-help ]
quick@sparq.org wrote:
>
> I have two questions regarding the use on __restrict__ qualifiers for function
> arguments in C++:
>
> 1) How does it interact with volatile?
>
> Example, given:
>
> void foo(volatile int* __restrict__ p1,
> volatile int* __restrict__ p2)
> {
> *p1 = 3;
> if (*p1 == 5) ...;
> *p2 = 4;
> }
>
> The most desireable for me would be that restrict would indicate that *p1 and
> *p2 were disjoint and allow reordering statement 3 to execute before either
> preceeding statement, but that volatile would indicate that the if expression
> would need to re-fetch *p1 and not assume the results of the first statement.
It doesn't matter. According to the definition of restrict in C99 [1],
During each execution of [Block] B, let L be any lvalue that has &L
based on P. If L is used to access the value of the object X that it
designates, and X is also modified (by any means), then the following
requirements apply: T shall not be const-qualified. Every other lvalue
used to access the value of X shall also have its address based on
P. Every access that modifies X shall be considered also to modify P,
for the purposes of this subclause."
So, if you access L other than via an address based on P, your program
is undefined, volatile notwithstanding.
[1] ISO/IEC 9899:1999 6.7.3.1 Formal definition of restrict
Andrew.
More information about the Gcc-help
mailing list