Понимание ограничить классификатор на примерах

restrict Поведение ключевого слова определено в C99 с помощью 6.7.3.1:

Let D be a declaration of an ordinary identifier that provides a means of designating an object P as a restrict-qualified pointer to type T.

If D appears inside a block and does not have storage class extern, let B denote the block. If D appears in the list of parameter declarations of a function definition, let B denote the associated block. Otherwise, let B denote the block of main (or the block of whatever function is called at program startup in a freestanding environment).

In what follows, a pointer expression E is said to be based on object P if (at some sequence point in the execution of B prior to the evaluation of E) modifying P to point to a copy of the array object into which it formerly pointed would change the value of E.119) Note that ''based'' is defined only for expressions with pointer types.

During each execution of 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. If P is assigned the value of a pointer expression E that is based on another restricted pointer object P2, associated with block B2, then either the execution of B2 shall begin before the execution of B, or the execution of B2 shall end prior to the assignment. If these requirements are not met, then the behavior is undefined.

Как и всем остальным, мне трудно понять все тонкости этого определения. В качестве ответа на этот вопрос я хотел бы видеть набор хороших примеров для каждого требования в 4-м абзаце случаев использования, которые будут нарушать это требование. Эта статья:

http://web.archive.org/web/20120225055041/http://developers.sun.com/solaris/articles/cc_restrict.html

делает хорошую работу по представлению правил в терминах "компилятор может предположить ..."; Расширение этого паттерна и связывание предположений, которые может сделать компилятор, и того, как они не выдерживают, с каждым примером было бы замечательно.

Ответы на вопрос(1)

Ваш ответ на вопрос