]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/doc/cpp/macros/directives-within-macro-arguments.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / cpp / macros / directives-within-macro-arguments.rst
1 ..
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.
5
6 .. index:: macro arguments and directives
7
8 .. _directives-within-macro-arguments:
9
10 Directives Within Macro Arguments
11 *********************************
12
13 Occasionally it is convenient to use preprocessor directives within
14 the arguments of a macro. The C and C++ standards declare that
15 behavior in these cases is undefined. GNU CPP
16 processes arbitrary directives within macro arguments in
17 exactly the same way as it would have processed the directive were the
18 function-like macro invocation not present.
19
20 If, within a macro invocation, that macro is redefined, then the new
21 definition takes effect in time for argument pre-expansion, but the
22 original definition is still used for argument replacement. Here is a
23 pathological example:
24
25 .. code-block:: c++
26
27 #define f(x) x x
28 f (1
29 #undef f
30 #define f 2
31 f)
32
33 which expands to
34
35 .. code-block:: c++
36
37 1 2 1 2
38
39 with the semantics described above.