Limit Keyword - Optimization and Smoothing Effects

I came across these two sections in the C11 standard, referring to the qualifier restrict:

1 #

6.7.3-8

An object that is accessed using a restricted pointer has a special association with this pointer. This association, defined in 6.7.3.1 below, requires that all calls to this object directly or indirectly use the value of this particular pointer .135) the use of a delimiter (for example, a register storage class) to facilitate optimization and remove all instances of the qualifier from all translation blocks for The preprocessing constituting the program does not change its meaning (i.e. the observed behavior).

Can you explain the meaning of the italic fragment to me? In my interpretation, since it does not change its meaning, it seems that the use is restrictsimply meaningless ...

2 #

6.7.3.1-6

The translator may ignore any or all of the use of restrictions.

What could be the effects of anti-aliasing? Can you show me some examples?

+5
source share
4 answers

The italic operator in the first quote basically said:

  • , , #define restrict , c-. - , , .

, . , .

+6

, , , . , :

int foo(int *a, int *b)
{
    *a = 5;
    *b = 6;
    return (*a + *b);
}

? 11, . 11, a == b, 12, , , b, . , , ,

1) stores 5 to a
2) stores 6 to b
3) loads a into a temporary register
4) adds the temp and 6
5) returns the sum

, a == b , , , , .

int foo(int * restrict a, int * restrict b)

, , :

1) store 5 to a
2) store 6 to b
3) return 11

, , . , , , , , () , , .

+8

, "" - .

+2

, , ( ).

This means that in the corresponding program all applications of the keyword restrictcomply with the rules, therefore, their removal will not change the result of the program.

In particular, in the corresponding program, no parameters passed as pointers restrictwill be similar to other pointers restrict. Otherwise, deleting a keyword can change the meaning of the program.

+2
source

All Articles