2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
6 .. index:: restricted pointers, restricted references, restricted this pointer
8 .. _restricted-pointers:
10 Restricting Pointer Aliasing
11 ****************************
13 As with the C front end, G++ understands the C99 feature of restricted pointers,
14 specified with the ``__restrict__``, or ``__restrict`` type
15 qualifier. Because you cannot compile C++ by specifying the :option:`-std=c99`
16 language flag, ``restrict`` is not a keyword in C++.
18 In addition to allowing restricted pointers, you can specify restricted
19 references, which indicate that the reference is not aliased in the local
24 void fn (int *__restrict__ rptr, int &__restrict__ rref)
29 In the body of ``fn``, :samp:`{rptr}` points to an unaliased integer and
30 :samp:`{rref}` refers to a (different) unaliased integer.
32 You may also specify whether a member function's :samp:`{this}` pointer is
33 unaliased by using ``__restrict__`` as a member function qualifier.
37 void T::fn () __restrict__
42 Within the body of ``T::fn``, :samp:`{this}` has the effective
43 definition ``T *__restrict__ const this``. Notice that the
44 interpretation of a ``__restrict__`` member function qualifier is
45 different to that of ``const`` or ``volatile`` qualifier, in that it
46 is applied to the pointer rather than the object. This is consistent with
47 other compilers that implement restricted pointers.
49 As with all outermost parameter qualifiers, ``__restrict__`` is
50 ignored in function definition matching. This means you only need to
51 specify ``__restrict__`` in a function definition, rather than
52 in a function prototype as well.