From Jason Turner

[cpp.scope]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp4_r40cqa/{from.md → to.md} +33 -3
tmp/tmp4_r40cqa/{from.md → to.md} RENAMED
@@ -13,18 +13,24 @@ A preprocessing directive of the form
13
 
14
  causes the specified identifier no longer to be defined as a macro name.
15
  It is ignored if the specified identifier is not currently defined as a
16
  macro name.
17
 
18
- The simplest use of this facility is to define a “manifest constant,” as
 
 
19
  in
20
 
21
  ``` cpp
22
  #define TABSIZE 100
23
  int table[TABSIZE];
24
  ```
25
 
 
 
 
 
26
  The following defines a function-like macro whose value is the maximum
27
  of its arguments. It has the advantages of working for any compatible
28
  types of the arguments and of generating in-line code without the
29
  overhead of function calling. It has the disadvantages of evaluating one
30
  or the other of its arguments a second time (including side effects) and
@@ -36,10 +42,14 @@ cannot have its address taken, as it has none.
36
  ```
37
 
38
  The parentheses ensure that the arguments and the resulting expression
39
  are bound properly.
40
 
 
 
 
 
41
  To illustrate the rules for redefinition and reexamination, the sequence
42
 
43
  ``` cpp
44
  #define x 3
45
  #define f(a) f(x * (a))
@@ -70,17 +80,22 @@ f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
70
  f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
71
  int i[] = { 1, 23, 4, 5, };
72
  char c[2][6] = { "hello", "" };
73
  ```
74
 
 
 
 
 
75
  To illustrate the rules for creating character string literals and
76
  concatenating tokens, the sequence
77
 
78
  ``` cpp
79
  #define str(s) # s
80
  #define xstr(s) str(s)
81
- #define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \ x ## s, x ## t)
 
82
  #define INCFILE(n) vers ## n
83
  #define glue(a, b) a ## b
84
  #define xglue(a, b) glue(a, b)
85
  #define HIGHLOW "hello"
86
  #define LOW LOW ", world"
@@ -114,10 +129,14 @@ fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0: \@n", s);
114
  ```
115
 
116
  Space around the `#` and `##` tokens in the macro definition is
117
  optional.
118
 
 
 
 
 
119
  To illustrate the rules for placemarker preprocessing tokens, the
120
  sequence
121
 
122
  ``` cpp
123
  #define t(x,y,z) x ## y ## z
@@ -130,17 +149,22 @@ results in
130
  ``` cpp
131
  int j[] = { 123, 45, 67, 89,
132
  10, 11, 12, };
133
  ```
134
 
 
 
 
 
135
  To demonstrate the redefinition rules, the following sequence is valid.
136
 
137
  ``` cpp
138
  #define OBJ_LIKE (1-1)
139
  #define OBJ_LIKE /* white space */ (1-1) /* other */
140
  #define FUNC_LIKE(a) ( a )
141
- #define FUNC_LIKE( a )( /* note the white space */ \ a /* other stuff on this line
 
142
  */ )
143
  ```
144
 
145
  But the following redefinitions are invalid:
146
 
@@ -149,10 +173,14 @@ But the following redefinitions are invalid:
149
  #define OBJ_LIKE (1 - 1) // different white space
150
  #define FUNC_LIKE(b) ( a ) // different parameter usage
151
  #define FUNC_LIKE(b) ( b ) // different parameter spelling
152
  ```
153
 
 
 
 
 
154
  Finally, to show the variable argument list macro facilities:
155
 
156
  ``` cpp
157
  #define debug(...) fprintf(stderr, __VA_ARGS__)
158
  #define showlist(...) puts(#__VA_ARGS__)
@@ -170,5 +198,7 @@ fprintf(stderr, "Flag");
170
  fprintf(stderr, "X = %d\n", x);
171
  puts("The first, second, and third items.");
172
  ((x>y) ? puts("x>y") : printf("x is %d but y is %d", x, y));
173
  ```
174
 
 
 
 
13
 
14
  causes the specified identifier no longer to be defined as a macro name.
15
  It is ignored if the specified identifier is not currently defined as a
16
  macro name.
17
 
18
+ [*Example 1*:
19
+
20
+ The simplest use of this facility is to define a “manifest constant”, as
21
  in
22
 
23
  ``` cpp
24
  #define TABSIZE 100
25
  int table[TABSIZE];
26
  ```
27
 
28
+ — *end example*]
29
+
30
+ [*Example 2*:
31
+
32
  The following defines a function-like macro whose value is the maximum
33
  of its arguments. It has the advantages of working for any compatible
34
  types of the arguments and of generating in-line code without the
35
  overhead of function calling. It has the disadvantages of evaluating one
36
  or the other of its arguments a second time (including side effects) and
 
42
  ```
43
 
44
  The parentheses ensure that the arguments and the resulting expression
45
  are bound properly.
46
 
47
+ — *end example*]
48
+
49
+ [*Example 3*:
50
+
51
  To illustrate the rules for redefinition and reexamination, the sequence
52
 
53
  ``` cpp
54
  #define x 3
55
  #define f(a) f(x * (a))
 
80
  f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
81
  int i[] = { 1, 23, 4, 5, };
82
  char c[2][6] = { "hello", "" };
83
  ```
84
 
85
+ — *end example*]
86
+
87
+ [*Example 4*:
88
+
89
  To illustrate the rules for creating character string literals and
90
  concatenating tokens, the sequence
91
 
92
  ``` cpp
93
  #define str(s) # s
94
  #define xstr(s) str(s)
95
+ #define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \
96
+ x ## s, x ## t)
97
  #define INCFILE(n) vers ## n
98
  #define glue(a, b) a ## b
99
  #define xglue(a, b) glue(a, b)
100
  #define HIGHLOW "hello"
101
  #define LOW LOW ", world"
 
129
  ```
130
 
131
  Space around the `#` and `##` tokens in the macro definition is
132
  optional.
133
 
134
+ — *end example*]
135
+
136
+ [*Example 5*:
137
+
138
  To illustrate the rules for placemarker preprocessing tokens, the
139
  sequence
140
 
141
  ``` cpp
142
  #define t(x,y,z) x ## y ## z
 
149
  ``` cpp
150
  int j[] = { 123, 45, 67, 89,
151
  10, 11, 12, };
152
  ```
153
 
154
+ — *end example*]
155
+
156
+ [*Example 6*:
157
+
158
  To demonstrate the redefinition rules, the following sequence is valid.
159
 
160
  ``` cpp
161
  #define OBJ_LIKE (1-1)
162
  #define OBJ_LIKE /* white space */ (1-1) /* other */
163
  #define FUNC_LIKE(a) ( a )
164
+ #define FUNC_LIKE( a )( /* note the white space */ \
165
+ a /* other stuff on this line
166
  */ )
167
  ```
168
 
169
  But the following redefinitions are invalid:
170
 
 
173
  #define OBJ_LIKE (1 - 1) // different white space
174
  #define FUNC_LIKE(b) ( a ) // different parameter usage
175
  #define FUNC_LIKE(b) ( b ) // different parameter spelling
176
  ```
177
 
178
+ — *end example*]
179
+
180
+ [*Example 7*:
181
+
182
  Finally, to show the variable argument list macro facilities:
183
 
184
  ``` cpp
185
  #define debug(...) fprintf(stderr, __VA_ARGS__)
186
  #define showlist(...) puts(#__VA_ARGS__)
 
198
  fprintf(stderr, "X = %d\n", x);
199
  puts("The first, second, and third items.");
200
  ((x>y) ? puts("x>y") : printf("x is %d but y is %d", x, y));
201
  ```
202
 
203
+ — *end example*]
204
+