From Jason Turner

[cpp.replace.general]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpkvkwef6t/{from.md → to.md} +150 -0
tmp/tmpkvkwef6t/{from.md → to.md} RENAMED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### General <a id="cpp.replace.general">[[cpp.replace.general]]</a>
2
+
3
+ Two replacement lists are identical if and only if the preprocessing
4
+ tokens in both have the same number, ordering, spelling, and whitespace
5
+ separation, where all whitespace separations are considered identical.
6
+
7
+ An identifier currently defined as an object-like macro (see below) may
8
+ be redefined by another `#define` preprocessing directive provided that
9
+ the second definition is an object-like macro definition and the two
10
+ replacement lists are identical, otherwise the program is ill-formed.
11
+ Likewise, an identifier currently defined as a function-like macro (see
12
+ below) may be redefined by another `#define` preprocessing directive
13
+ provided that the second definition is a function-like macro definition
14
+ that has the same number and spelling of parameters, and the two
15
+ replacement lists are identical, otherwise the program is ill-formed.
16
+
17
+ [*Example 1*:
18
+
19
+ The following sequence is valid:
20
+
21
+ ``` cpp
22
+ #define OBJ_LIKE (1-1)
23
+ #define OBJ_LIKE /* whitespace */ (1-1) /* other */
24
+ #define FUNC_LIKE(a) ( a )
25
+ #define FUNC_LIKE( a )( /* note the whitespace */ \
26
+ a /* other stuff on this line
27
+ */ )
28
+ ```
29
+
30
+ But the following redefinitions are invalid:
31
+
32
+ ``` cpp
33
+ #define OBJ_LIKE (0) // different token sequence
34
+ #define OBJ_LIKE (1 - 1) // different whitespace
35
+ #define FUNC_LIKE(b) ( a ) // different parameter usage
36
+ #define FUNC_LIKE(b) ( b ) // different parameter spelling
37
+ ```
38
+
39
+ — *end example*]
40
+
41
+ There shall be whitespace between the identifier and the replacement
42
+ list in the definition of an object-like macro.
43
+
44
+ If the *identifier-list* in the macro definition does not end with an
45
+ ellipsis, the number of arguments (including those arguments consisting
46
+ of no preprocessing tokens) in an invocation of a function-like macro
47
+ shall equal the number of parameters in the macro definition. Otherwise,
48
+ there shall be at least as many arguments in the invocation as there are
49
+ parameters in the macro definition (excluding the `...`). There shall
50
+ exist a `)` preprocessing token that terminates the invocation.
51
+
52
+ The identifiers `__VA_ARGS__` and `__VA_OPT__` shall occur only in the
53
+ *replacement-list* of a function-like macro that uses the ellipsis
54
+ notation in the parameters.
55
+
56
+ A parameter identifier in a function-like macro shall be uniquely
57
+ declared within its scope.
58
+
59
+ The identifier immediately following the `define` is called the *macro
60
+ name*. There is one name space for macro names. Any whitespace
61
+ characters preceding or following the replacement list of preprocessing
62
+ tokens are not considered part of the replacement list for either form
63
+ of macro.
64
+
65
+ If a `#` preprocessing token, followed by an identifier, occurs
66
+ lexically at the point at which a preprocessing directive can begin, the
67
+ identifier is not subject to macro replacement.
68
+
69
+ A preprocessing directive of the form
70
+
71
+ ``` bnf
72
+ '# define' identifier replacement-list new-line
73
+ ```
74
+
75
+ defines an *object-like macro* that causes each subsequent instance of
76
+ the macro name[^5]
77
+
78
+ to be replaced by the replacement list of preprocessing tokens that
79
+ constitute the remainder of the directive.[^6]
80
+
81
+ The replacement list is then rescanned for more macro names as specified
82
+ below.
83
+
84
+ [*Example 2*:
85
+
86
+ The simplest use of this facility is to define a “manifest constant”, as
87
+ in
88
+
89
+ ``` cpp
90
+ #define TABSIZE 100
91
+ int table[TABSIZE];
92
+ ```
93
+
94
+ — *end example*]
95
+
96
+ A preprocessing directive of the form
97
+
98
+ ``` bnf
99
+ '# define' identifier lparen identifier-listₒₚₜ ')' replacement-list new-line
100
+ '# define' identifier lparen '...' ')' replacement-list new-line
101
+ '# define' identifier lparen identifier-list ', ...' ')' replacement-list new-line
102
+ ```
103
+
104
+ defines a *function-like macro* with parameters, whose use is similar
105
+ syntactically to a function call. The parameters are specified by the
106
+ optional list of identifiers. Each subsequent instance of the
107
+ function-like macro name followed by a `(` as the next preprocessing
108
+ token introduces the sequence of preprocessing tokens that is replaced
109
+ by the replacement list in the definition (an invocation of the macro).
110
+ The replaced sequence of preprocessing tokens is terminated by the
111
+ matching `)` preprocessing token, skipping intervening matched pairs of
112
+ left and right parenthesis preprocessing tokens. Within the sequence of
113
+ preprocessing tokens making up an invocation of a function-like macro,
114
+ new-line is considered a normal whitespace character.
115
+
116
+ The sequence of preprocessing tokens bounded by the outside-most
117
+ matching parentheses forms the list of arguments for the function-like
118
+ macro. The individual arguments within the list are separated by comma
119
+ preprocessing tokens, but comma preprocessing tokens between matching
120
+ inner parentheses do not separate arguments. If there are sequences of
121
+ preprocessing tokens within the list of arguments that would otherwise
122
+ act as preprocessing directives,[^7]
123
+
124
+ the behavior is undefined.
125
+
126
+ [*Example 3*:
127
+
128
+ The following defines a function-like macro whose value is the maximum
129
+ of its arguments. It has the disadvantages of evaluating one or the
130
+ other of its arguments a second time (including side effects) and
131
+ generating more code than a function if invoked several times. It also
132
+ cannot have its address taken, as it has none.
133
+
134
+ ``` cpp
135
+ #define max(a, b) ((a) > (b) ? (a) : (b))
136
+ ```
137
+
138
+ The parentheses ensure that the arguments and the resulting expression
139
+ are bound properly.
140
+
141
+ — *end example*]
142
+
143
+ If there is a `...` immediately preceding the `)` in the function-like
144
+ macro definition, then the trailing arguments (if any), including any
145
+ separating comma preprocessing tokens, are merged to form a single item:
146
+ the *variable arguments*. The number of arguments so combined is such
147
+ that, following merger, the number of arguments is either equal to or
148
+ one more than the number of parameters in the macro definition
149
+ (excluding the `...`).
150
+