Argument Prescan - Red Hat ENTERPRISE LINUX 3 - USING CPP Using Instructions

Using cpp, the c preprocessor
Hide thumbs Also See for ENTERPRISE LINUX 3 - USING CPP:
Table of Contents

Advertisement

Chapter 3. Macros
then the macro
EPERM
it's used in running text. You can tell that it's a macro with
define numeric constants with an
If a macro
expands to use a macro
x
self-reference of
.
x
x
#define x (4 + y)
#define y (2 * x)
then
and
expand as follows:
x
y
x
==> (4 + y)
==> (4 + (2 * x))
y
==> (2 * x)
==> (2 * (4 + y))
Each macro is expanded when it appears in the definition of the other macro, but not when it indirectly
appears in its own definition.

3.9.6. Argument Prescan

Macro arguments are completely macro-expanded before they are substituted into a macro body, un-
less they are stringified or pasted with other tokens. After substitution, the entire macro body, including
the substituted arguments, is scanned again for macros to be expanded. The result is that the arguments
are scanned twice to expand macro calls in them.
Most of the time, this has no effect. If the argument contained any macro calls, they are expanded
during the first scan. The result therefore contains no macro calls, so the second scan does not change
it. If the argument were substituted as given, with no prescan, the single remaining scan would find
the same macro calls and produce the same results.
You might expect the double scan to change the results when a self-referential macro is used in an
argument of another macro (Refer to Section 3.9.5 Self-Referential Macros): the self-referential macro
would be expanded once in the first scan, and a second time in the second scan. However, this is not
what happens. The self-references that do not expand in the first scan are marked so that they will not
expand in the second scan either.
You might wonder, "Why mention the prescan, if it makes no difference? And why not skip it and
make the preprocessor faster?" The answer is that the prescan does make a difference in three special
cases:
Nested calls to a macro.
We say that nested calls to a macro occur when a macro's argument contains a call to that very
macro. For example, if
to
. The desired expansion is made by expanding
f
of
. The prescan causes the expected result to happen. Without the prescan,
f
substituted as an argument, and the inner use of
self-reference and would not be expanded.
Macros that call other macros that stringify or concatenate.
expands to
. Effectively, it is left alone by the preprocessor whenever
EPERM
, but have
enum
, and the expansion of
y
is not expanded in this case either. Thus, if we have
is a macro that expects one argument,
f
. You might do this if you want to
#ifdef
be true for each constant.
#ifdef
refers to the macro
y
f (f (1))
and substituting that into the definition
f (1)
would appear during the main scan as an indirect
f
31
, that is an indirect
x
is a nested pair of calls
itself would be
f (1)

Advertisement

Table of Contents
loading

This manual is also suitable for:

Enterprise linux 3

Table of Contents