Using the restrict
keyword improves
performance as shown in the previous topic. However there are issues if the keyword is
used inappropriately. 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
restrict
Keyword
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 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 first example code below shows the working inline function call, in which
the pointer p
and the pointer q
are used in different scopes.
The undefined behavior occurs when the restrict
pointers are used within the same scope, such as pointers
p
and q
in
the following example.