Using the restrict keyword improves performance as shown in the previous topic.
However, inappropriate use causes issues. The __restrict child pointers must be
used in a different block-level scope than the parent pointers, such as pointer p and q as shown in the
following example.
Working Example 1
Use of parent pointers in the same scope might break the __restrict contract which produces an undefined
behavior, such as pointers p and q in the following example.
Working Example 2
This can also happen during the load
operation, as shown in the green text (return *p;) in the following
figure.
The undefined behavior occurs when the restrict pointers are used within the
same scope, such as pointers p and q in the following example.
Working Example with Inline Function
The following code shows the working inline function call, in which pointer
p and pointer q are used in different scopes.
Undefined behavior can occur when you use restrict pointers
in the same scope. For example, pointers p and q
in the following code cause this issue.