~ubuntu-branches/ubuntu/edgy/mcpp/edgy

« back to all changes in this revision

Viewing changes to test-t/n_std.t

  • Committer: Bazaar Package Importer
  • Author(s): NIIBE Yutaka
  • Date: 2004-10-23 23:18:57 UTC
  • Revision ID: james.westby@ubuntu.com-20041023231857-93z8ff2dgp7m7dpy
Tags: upstream-2.4.1
ImportĀ upstreamĀ versionĀ 2.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      n_std.t
 
3
 *
 
4
 * 1998/08      made public                                     kmatsui
 
5
 * 2002/08      revised not to conflict with C99 Standard       kmatsui
 
6
 *
 
7
 *   Samples to test C++ Standard preprocessing.
 
8
 *   Preprocessor must process these samples as shown in each comments.
 
9
 *   Preprocessor must process also #error directive properly, which is not
 
10
 * included here because the directive might cause translator to terminate.
 
11
 */
 
12
 
 
13
 
 
14
#define ZERO_TOKEN
 
15
#define TWO_ARGS        a,b
 
16
#define MACRO_0         0
 
17
#define MACRO_1         1
 
18
#define sub( x, y)      (x - y)
 
19
#define str( a)         # a
 
20
#define glue( a, b)     a ## b
 
21
#define xglue( a, b)    glue( a, b)
 
22
 
 
23
 
 
24
/* n_1.t:   Conversion of trigraph sequences.   */
 
25
 
 
26
/* 1.1: The following 9 sequences are valid trigraph sequences. */
 
27
/*  [ ] \ ^ { } | ~ #;  */
 
28
    ??( ??) ??/ ??' ??< ??> ??! ??- ??=;
 
29
 
 
30
/* 1.2: In directive line.  */
 
31
/*  ab | cd;    */
 
32
??= define  OR( a, b)   a ??! b
 
33
    OR( ab, cd);
 
34
 
 
35
/* 1.3: Any sequence other than above 9 is not a trigraph sequence. */
 
36
/*  ?? ??? ??% ??^ ?#;  */
 
37
    ?? ??? ??% ??^ ???=;
 
38
 
 
39
 
 
40
/* n_2.t:   Line splicing by <backslash><newline> sequence. */
 
41
 
 
42
/* 2.1: In a #define directive line, between the parameter list and the
 
43
        replacement text.   */
 
44
/*  ab + cd + ef;   */
 
45
#define FUNC( a, b, c)  \
 
46
        a + b + c
 
47
    FUNC( ab, cd, ef);
 
48
 
 
49
/* 2.2: In a #define directive line, among the parameter list and among the
 
50
        replacement text.   */
 
51
/*  ab + cd + ef;   */
 
52
#undef  FUNC
 
53
#define FUNC( a, b  \
 
54
        , c)        \
 
55
        a + b       \
 
56
        + c
 
57
    FUNC( ab, cd, ef);
 
58
 
 
59
/* 2.3: In a string literal.    */
 
60
/*  "abcde" */
 
61
    "abc\
 
62
de"
 
63
 
 
64
/* 2.4: <backslash><newline> in midst of an identifier. */
 
65
/*  abcde   */
 
66
    abc\
 
67
de
 
68
 
 
69
/* 2.5: <backslash><newline> by trigraph.   */
 
70
/*  abcde   */
 
71
    abc??/
 
72
de
 
73
 
 
74
 
 
75
/* n_3.t:   Handling of comment.    */
 
76
 
 
77
/* 3.1: A comment is converted to one space.    */
 
78
/*  abc de  */
 
79
    abc/* comment */de
 
80
 
 
81
/* 3.2: // is not a comment of C.   */
 
82
#if 0   /* This feature is obsolete now.  */
 
83
/*  / / is not a comment of C   */
 
84
    // is not a comment of C
 
85
#endif
 
86
 
 
87
/* 3.3: Comment is parsed prior to the parsing of preprocessing directive.  */
 
88
/*  abcd    */
 
89
#if     0
 
90
    "nonsence"; /*
 
91
#else
 
92
    still in
 
93
    comment     */
 
94
#else
 
95
#define MACRO_abcd  /*
 
96
    in comment
 
97
    */  abcd
 
98
#endif
 
99
    MACRO_abcd
 
100
 
 
101
 
 
102
/* n_4.t:   Special tokens. */
 
103
 
 
104
/* 4.1: Digraph spellings in directive line.    */
 
105
/*  "abc";  */
 
106
%: define  stringize( a)    %: a
 
107
 
 
108
    stringize( abc);
 
109
 
 
110
/* 4.2: Digraph spellings are retained in stringization.    */
 
111
/*  "<:";   */
 
112
    stringize( <:);
 
113
 
 
114
 
 
115
/* n_5.t:   Spaces or tabs are allowed at any place in pp-directive line,
 
116
        including between the top of a pp-directive line and '#', and between
 
117
        the '#' and the directive. */
 
118
 
 
119
/* 5.1: */
 
120
/*  |**|[TAB]# |**|[TAB]define |**| MACRO_abcde[TAB]|**| abcde |**| */
 
121
/**/    # /**/  define /**/ MACRO_abcde /**/ abcde /**/
 
122
/*  abcde   */
 
123
    MACRO_abcde
 
124
 
 
125
 
 
126
/* n_6.t:   #include directive. */
 
127
 
 
128
/* 6.1: Header-name quoted by " and " as well as by < and > can include
 
129
        standard headers.   */
 
130
/* Note: Standard headers can be included any times.    */
 
131
#include    "ctype.h"
 
132
#include    <ctype.h>
 
133
 
 
134
/* 6.2: Macro is allowed in #include line.  */
 
135
#define HEADER  "header.h"
 
136
/* Before file inclusion:   #include "header.h" */
 
137
#include    HEADER
 
138
/*  abc */
 
139
    MACRO_abc
 
140
 
 
141
/* 6.3: With macro nonsence but legal.  */
 
142
#undef  MACRO_abc
 
143
#include    ZERO_TOKEN HEADER ZERO_TOKEN
 
144
/*  abc */
 
145
    MACRO_abc
 
146
 
 
147
 
 
148
/* n_7.t:   #line directive.    */
 
149
 
 
150
/* 7.1: Line number and filename.   */
 
151
/*  1234; "cpp";    */
 
152
#line   1234    "cpp"
 
153
    __LINE__; __FILE__;
 
154
 
 
155
/* 7.2: Filename argument is optional.  */
 
156
/*  2345; "cpp";    */
 
157
#line   2345
 
158
    __LINE__; __FILE__;
 
159
 
 
160
/* 7.3: Argument with macro.    */
 
161
/*  3456; "n_7.t";  */
 
162
#define LINE_AND_FILENAME   3456 "n_7.t"
 
163
#line   LINE_AND_FILENAME
 
164
    __LINE__; __FILE__;
 
165
 
 
166
/* Restore to correct line number and filename. */
 
167
#line   167 "n_std.t"
 
168
 
 
169
 
 
170
/* n_9.t:   #pragma directive.  */
 
171
 
 
172
/* 9.1: Any #pragma directive should be processed or ignored, should not
 
173
        be diagnosed as an error.   */
 
174
#pragma __once
 
175
#pragma who knows ?
 
176
 
 
177
 
 
178
/* n_10.t:  #if, #elif, #else and #endif pp-directive.  */
 
179
 
 
180
/* 10.1:    */
 
181
/* Note: an undefined identifier in #if expression is replaced to 0.    */
 
182
/*  1;  */
 
183
#if     a
 
184
    a;
 
185
#elif   MACRO_0
 
186
    MACRO_0;
 
187
#elif   MACRO_1         /* Valid block  */
 
188
    MACRO_1;
 
189
#else
 
190
    0;
 
191
#endif
 
192
 
 
193
/* 10.2:    Comments must be processed even if in skipped #if block.    */
 
194
/* At least tokenization of string literal and character constant is necessary
 
195
        to process comments, e.g. /* is not a comment mark in string literal.
 
196
 */
 
197
#ifdef  UNDEFINED
 
198
    /* Comment  */
 
199
    "in literal /* is not a comment"
 
200
#endif
 
201
 
 
202
 
 
203
/* n_11.t:  Operator "defined" in #if or #elif directive.   */
 
204
 
 
205
/* 11.1:    */
 
206
#undef  MACRO_abc
 
207
#define MACRO_abc   abc
 
208
/*  abc;    */
 
209
/*  abc;    */
 
210
#if     defined a
 
211
    a;
 
212
#else
 
213
    MACRO_abc;
 
214
#endif
 
215
#if     defined (MACRO_abc)
 
216
    MACRO_abc;
 
217
#else
 
218
    0;
 
219
#endif
 
220
 
 
221
/* 11.2:    "defined" is an unary operator whose result is 1 or 0.  */
 
222
#if     defined MACRO_0 * 3 != 3
 
223
    Bad handling of "defined" operator.
 
224
#endif
 
225
#if     (!defined ZERO_TOKEN != 0) || (-defined ZERO_TOKEN != -1)
 
226
    Bad grouping of "defined", !, - operator.
 
227
#endif
 
228
 
 
229
 
 
230
/* n_12.t:  Integer preprocessing number token and type of #if expression.  */
 
231
 
 
232
#include    <limits.h>
 
233
 
 
234
/* 12.1:    Type long.  */
 
235
#if     LONG_MAX <= LONG_MIN
 
236
    Bad evaluation of long.
 
237
#endif
 
238
#if     LONG_MAX <= 1073741823  /* 0x3FFFFFFF   */
 
239
    Bad evaluation of long.
 
240
#endif
 
241
 
 
242
/* 12.2:    Type unsigned long. */
 
243
#if     ULONG_MAX / 2 < LONG_MAX
 
244
    Bad evaluation of unsigned long.
 
245
#endif
 
246
 
 
247
/* 12.3:    Octal number.   */
 
248
#if     0177777 != 65535
 
249
    Bad evaluation of octal number.
 
250
#endif
 
251
 
 
252
/* 12.4:    Hexadecimal number. */
 
253
#if     0Xffff != 65535 || 0xFfFf != 65535
 
254
    Bad evaluation of hexadecimal number.
 
255
#endif
 
256
 
 
257
/* 12.5:    Suffix 'L' or 'l'.  */
 
258
#if     0L != 0 || 0l != 0
 
259
    Bad evaluation of 'L' suffix.
 
260
#endif
 
261
 
 
262
/* 12.6:    Suffix 'U' or 'u'.  */
 
263
#if     1U != 1 || 1u != 1
 
264
    Bad evaluation of 'U' suffix.
 
265
#endif
 
266
 
 
267
/* 12.7:    Negative integer.   */
 
268
#if     0 <= -1
 
269
    Bad evaluation of negative number.
 
270
#endif
 
271
 
 
272
 
 
273
/* n_13.t:  Valid operators in #if expression.  */
 
274
 
 
275
/* Valid operators are (precedence in this order) :
 
276
    defined, (unary)+, (unary)-, ~, !,
 
277
    *, /, %,
 
278
    +, -,
 
279
    <<, >>,
 
280
    <, >, <=, >=,
 
281
    ==, !=,
 
282
    &,
 
283
    ^,
 
284
    |,
 
285
    &&,
 
286
    ||,
 
287
    ? :
 
288
 */
 
289
 
 
290
/* 13.1:    Bit shift.  */
 
291
#if     1 << 2 != 4 || 8 >> 1 != 4
 
292
    Bad arithmetic of <<, >> operators.
 
293
#endif
 
294
 
 
295
/* 13.2:    Bitwise operators.  */
 
296
#if     (3 ^ 5) != 6 || (3 | 5) != 7 || (3 & 5) != 1
 
297
    Bad arithmetic of ^, |, & operators.
 
298
#endif
 
299
 
 
300
/* 13.3:    Result of ||, && operators is either of 1 or 0. */
 
301
#if     (2 || 3) != 1 || (2 && 3) != 1 || (0 || 4) != 1 || (0 && 5) != 0
 
302
    Bad arithmetic of ||, && operators.
 
303
#endif
 
304
 
 
305
/* 13.4:    ?, : operator.  */
 
306
#if     (0 ? 1 : 2) != 2
 
307
    Bad arithmetic of ?: operator.
 
308
#endif
 
309
 
 
310
 
 
311
/* n_13_5.t:    Arithmetic conversion in #if expressions.   */
 
312
 
 
313
/* 13.5:    The usual arithmetic conversion is not performed on bit shift.  */
 
314
#if     -1 << 3U > 0
 
315
    Bad conversion of bit shift operands.
 
316
#endif
 
317
 
 
318
/* 13.6:    Usual arithmetic conversions.   */
 
319
#if     -1 <= 0U        /* -1 is converted to unsigned long.    */
 
320
    Bad arithmetic conversion.
 
321
#endif
 
322
 
 
323
#if     -1 * 1U <= 0
 
324
    Bad arithmetic conversion.
 
325
#endif
 
326
 
 
327
/* Second and third operands of conditional operator are converted to the
 
328
        same type, thus -1 is converted to unsigned long.    */
 
329
#if     (1 ? -1 : 0U) <= 0
 
330
    Bad arithmetic conversion.
 
331
#endif
 
332
 
 
333
 
 
334
/* n_13_7.t:    Short-circuit evaluation of #if expression. */
 
335
 
 
336
/* 13.7:    10/0 or 10/MACRO_0 are never evaluated, "divide by zero" error
 
337
        cannot occur.   */
 
338
/*  Valid block */
 
339
#if     0 && 10 / 0
 
340
    Block to be skipped
 
341
#endif
 
342
#if     not_defined && 10 / not_defined
 
343
    Block to be skipped
 
344
#endif
 
345
#if     MACRO_0 && 10 / MACRO_0 > 1
 
346
    Block to be skipped
 
347
#endif
 
348
#if     MACRO_0 ? 10 / MACRO_0 : 0
 
349
    Block to be skipped
 
350
#endif
 
351
#if     MACRO_0 == 0 || 10 / MACRO_0 > 1
 
352
    Valid block
 
353
#else
 
354
    Block to be skipped
 
355
#endif
 
356
 
 
357
 
 
358
/* n_13_8.t:    Grouping of sub-expressions in #if expression.  */
 
359
 
 
360
/* 13.8:    Unary operators are grouped from right to left. */
 
361
#if     (- -1 != 1) || (!!9 != 1) || (-!+!9 != -1) || (~~1 != 1)
 
362
    Bad grouping of -, +, !, ~ in #if expression.
 
363
#endif
 
364
 
 
365
/* 13.9:    ?: operators are grouped from right to left.    */
 
366
#if     (1 ? 2 ? 3 ? 3 : 2 : 1 : 0) != 3
 
367
    Bad grouping of ? : in #if expression.
 
368
#endif
 
369
 
 
370
/* 13.10:   Other operators are grouped from left to right. */
 
371
#if     (15 >> 2 >> 1 != 1) || (3 << 2 << 1 != 24)
 
372
    Bad grouping of >>, << in #if expression.
 
373
#endif
 
374
 
 
375
/* 13.11:   Test of precedence. */
 
376
#if     3*10/2 >> !0*2 >> !+!-9 != 1
 
377
    Bad grouping of -, +, !, *, /, >> in #if expression.
 
378
#endif
 
379
 
 
380
/* 13.12:   Overall test.  Grouped as:
 
381
        ((((((+1 - -1 - ~~1 - -!0) & 6) | ((8 % 9) ^ (-2 * -2))) >> 1) == 7)
 
382
        ? 7 : 0) != 7
 
383
    evaluated to FALSE.
 
384
 */
 
385
#if     (((+1- -1-~~1- -!0&6|8%9^-2*-2)>>1)==7?7:0)!=7
 
386
    Bad arithmetic of #if expression.
 
387
#endif
 
388
 
 
389
 
 
390
/* n_13_13.t:   #if expression with macros. */
 
391
 
 
392
#define and             &&
 
393
#define or              ||
 
394
#define not_eq          !=
 
395
#define bitor           |
 
396
 
 
397
/* 13.13:   With macros expanding to operators. */
 
398
/*  Valid block */
 
399
#if     (1 bitor 2) == 3 and 4 not_eq 5 or 0
 
400
    /* #if (1 | 2) == 3 && 4 != 5 || 0  */
 
401
    Valid block
 
402
#else
 
403
    Block to be skipped
 
404
#endif
 
405
 
 
406
/* 13.14:   With macros expanding to 0 token, nonsence but legal expression.*/
 
407
/*  Valid block */
 
408
#if     ZERO_TOKEN MACRO_1 ZERO_TOKEN > ZERO_TOKEN MACRO_0 ZERO_TOKEN
 
409
    /* #if 1 > 0    */
 
410
    Valid block
 
411
#else
 
412
    Block to be skipped
 
413
#endif
 
414
 
 
415
 
 
416
/* n_15.t:  #ifdef, #ifndef directives. */
 
417
 
 
418
/* 15.1:    #ifdef directive.   */
 
419
/*  Valid block */
 
420
#ifdef  MACRO_1
 
421
    Valid block
 
422
#else
 
423
    Block to be skipped
 
424
#endif
 
425
 
 
426
/* 15.2:    #ifndef directive.  */
 
427
/*  Valid block */
 
428
#ifndef MACRO_1
 
429
    Block to be skipped
 
430
#else
 
431
    Valid block
 
432
#endif
 
433
 
 
434
 
 
435
/* n_18.t:  #define directive.  */
 
436
 
 
437
/* Excerpts from ISO C 6.8.3 "Examples".    */
 
438
#define OBJ_LIKE        (1-1)
 
439
#define FTN_LIKE(a)     ( a )
 
440
 
 
441
/* 18.1:    Definition of an object-like macro. */
 
442
/*  (1-1);  */
 
443
    OBJ_LIKE;
 
444
/* Macro defined to no token.   */
 
445
/*  ;   */
 
446
    ZERO_TOKEN;
 
447
 
 
448
/* 18.2:    Definition of a function-like macro.    */
 
449
/*  ( c );  */
 
450
    FTN_LIKE( c);
 
451
 
 
452
/* 18.3:    Spelling in string identical to parameter is not a parameter.   */
 
453
/*  "n1:n2";    */
 
454
#define STR( n1, n2)    "n1:n2"
 
455
    STR( 1, 2);
 
456
 
 
457
 
 
458
/* n_19.t:  Valid re-definitions of macros. */
 
459
 
 
460
/* 19.1:    */
 
461
#define OBJ_LIKE    /* white space */  (1-1) /* other */
 
462
 
 
463
/* 19.2:    */
 
464
#define FTN_LIKE( a     )(  /* note the white space */  \
 
465
                        a  /* other stuff on this line
 
466
                           */ )
 
467
/*  ( c );  */
 
468
    FTN_LIKE( c);
 
469
 
 
470
 
 
471
/* n_20.t:  Definition of macro lexically identical to keyword. */
 
472
 
 
473
/* 20.1:    */
 
474
/*  double fl;  */
 
475
#define float   double
 
476
    float   fl;
 
477
 
 
478
 
 
479
/* n_21.t:  Tokenization (No preprocessing tokens are merged implicitly).   */
 
480
 
 
481
/* 21.1:    */
 
482
/*  - - -a; */
 
483
#define MINUS   -
 
484
    -MINUS-a;
 
485
 
 
486
 
 
487
/* n_22.t:  Tokenization of preprocessing number.   */
 
488
 
 
489
#define EXP         1
 
490
 
 
491
/* 22.1:    12E+EXP is a preprocessing number, EXP is not expanded. */
 
492
/*  12E+EXP;    */
 
493
    12E+EXP;
 
494
 
 
495
/* 22.2:    .2e-EXP is also a preprocessing number. */
 
496
/*  .2e-EXP;    */
 
497
    .2e-EXP;
 
498
 
 
499
/* 22.3:    + or - is allowed only following E or e, 12+EXP is not a
 
500
        preprocessing number.   */
 
501
/* Three tokens: 12 + 1;    */
 
502
    12+EXP;
 
503
 
 
504
 
 
505
/* n_23.t:  ## operator in macro definition.    */
 
506
 
 
507
/* 23.1:    */
 
508
/*  xy; */
 
509
    glue( x, y);
 
510
 
 
511
/* 23.2:    Generate a preprocessing number.    */
 
512
/*  .12e+2; */
 
513
#undef  EXP
 
514
#define EXP     2
 
515
    xglue( .12e+, EXP);
 
516
 
 
517
 
 
518
/* n_24.t:  # operator in macro definition. */
 
519
 
 
520
/* 24.1:    */
 
521
/*  "a+b";  */
 
522
    str( a+b);
 
523
 
 
524
/* 24.2:    White spaces between tokens of operand are converted to one space.
 
525
 */
 
526
/*  "ab + cd";  */
 
527
    str(    ab  /* comment */   +
 
528
        cd  );
 
529
 
 
530
/* 24.3:    \ is inserted before \ and " in or surrounding literals and no
 
531
        other character is inserted to anywhere.    */
 
532
/*  "'\"' + \"' \\\"\"";    */
 
533
    str( '"' + "' \"");
 
534
 
 
535
/* 24.4:    Line splicing by <backslash><newline> is done prior to token
 
536
        parsing.    */
 
537
/*  "\"abc\"";  */
 
538
    str( "ab\
 
539
c");
 
540
 
 
541
 
 
542
/* n_25.t:  Macro arguments are pre-expanded (unless the argument is an
 
543
        operand of # or ## operator) separately, that is, are macro-replaced
 
544
        completely prior to rescanning. */
 
545
 
 
546
/* 25.1:    "TWO_ARGS" is read as one argument to "sub", then expanded to
 
547
        "a,b", then "x" is substituted by "a,b".    */
 
548
/*  (a,b - 1);  */
 
549
    sub( TWO_ARGS, 1);
 
550
 
 
551
/* 25.2:    An argument pre-expanded to 0-token.    */
 
552
/*  ( - 1); */
 
553
    sub( ZERO_TOKEN, 1);
 
554
 
 
555
/* 25.3:    "glue( a, b)" is pre-expanded.  */
 
556
/*  abc;    */
 
557
    xglue( glue( a, b), c);
 
558
 
 
559
/* 25.4:    Operands of ## operator are not pre-expanded.   */
 
560
/*  MACRO_0MACRO_1; */
 
561
    glue( MACRO_0, MACRO_1);
 
562
 
 
563
/* 25.5:    Operand of # operator is not pre-expanded.  */
 
564
/*  "ZERO_TOKEN";   */
 
565
    str( ZERO_TOKEN);
 
566
 
 
567
 
 
568
/* n_26.t:  The name once replaced is not furthur replaced. */
 
569
 
 
570
/* 26.1:    Directly recursive macro definition.    */
 
571
/*  Z[0];   */
 
572
#define Z   Z[0]
 
573
    Z;
 
574
 
 
575
/* 26.2:    Intermediately recursive macro definition.  */
 
576
/*  AB; */
 
577
#define AB  BA
 
578
#define BA  AB
 
579
    AB;
 
580
 
 
581
/* 26.3:    Directly recursive function-like macro definition.  */
 
582
/*  x + f(x);   */
 
583
#define f(a)    a + f(a)
 
584
    f( x);
 
585
 
 
586
/* 26.4:    Intermediately recursive function-like macro definition.    */
 
587
/*  x + x + g( x);  */
 
588
#define g(a)    a + h( a)
 
589
#define h(a)    a + g( a)
 
590
    g( x);
 
591
 
 
592
/* 26.5:    Rescanning encounters the non-replaced macro name.  */
 
593
/*  Z[0] + f( Z[0]);    */
 
594
    f( Z);
 
595
 
 
596
 
 
597
/* n_27.t:  Rescanning of a macro expand any macro call in the replacement
 
598
        text after substitution of parameters by pre-expanded-arguments.  This
 
599
        re-examination may involve the succeding sequences from the source
 
600
        file (what a queer thing!). */
 
601
 
 
602
/* 27.1:    Cascaded use of object-like macros. */
 
603
/*  1 + 2 + 3 + 4 + 5 + 6 + 7 + 8;  */
 
604
#define NEST8   NEST7 + 8
 
605
#define NEST7   NEST6 + 7
 
606
#define NEST6   NEST5 + 6
 
607
#define NEST5   NEST4 + 5
 
608
#define NEST4   NEST3 + 4
 
609
#define NEST3   NEST2 + 3
 
610
#define NEST2   NEST1 + 2
 
611
#define NEST1   1
 
612
    NEST8;
 
613
 
 
614
/* 27.2:    Cascaded use of function-like macros.   */
 
615
/*  (1) + (1 + 2) + 1 + 2 + 1 + 2 + 3 + 1 + 2 + 3 + 4;  */
 
616
#define FUNC4( a, b)    FUNC3( a, b) + NEST4
 
617
#define FUNC3( a, b)    FUNC2( a, b) + NEST3
 
618
#define FUNC2( a, b)    FUNC1( a, b) + NEST2
 
619
#define FUNC1( a, b)    (a) + (b)
 
620
    FUNC4( NEST1, NEST2);
 
621
 
 
622
/* 27.3:    An identifier generated by ## operator is subject to expansion. */
 
623
/*  1;  */
 
624
    glue( MACRO_, 1);
 
625
 
 
626
#define head            sub(
 
627
#define math( op, a, b) op( (a), (b))
 
628
 
 
629
/* 27.4:    'sub' as an argument of math() is not pre-expanded, since '(' is
 
630
        missing.    */
 
631
/*  ((a) - (b));    */
 
632
    math( sub, a, b);
 
633
 
 
634
/* 27.5:    Queer thing.    */
 
635
/*  (a - b);    */
 
636
    head a,b );
 
637
 
 
638
 
 
639
/* n_28.t:  __FILE__, __LINE__, __DATE__, __TIME__, __STDC__ and
 
640
        __STDC_VERSION__ are predefined.    */
 
641
 
 
642
/* 28.1:    */
 
643
/*  "n_std.t";  */
 
644
    __FILE__;
 
645
 
 
646
/* 28.2:    */
 
647
/*  647;    */
 
648
    __LINE__;
 
649
 
 
650
/* 28.3:    */
 
651
/*  "Aug  1 2001";  */
 
652
    __DATE__;
 
653
 
 
654
/* 28.4:    */
 
655
/*  "21:42:22"; */
 
656
    __TIME__;
 
657
 
 
658
/* 28.5:    */
 
659
/*  1;  */
 
660
    __STDC__;
 
661
 
 
662
/* 28.6:    */
 
663
/*  199409L;    */
 
664
/* In C99, the value of this macro is 199901L   */
 
665
    __STDC_VERSION__;
 
666
 
 
667
/* 28.7:    __LINE__, __FILE__ in an included file. */
 
668
/*  3; "line.h";    */
 
669
#include    "line.h"
 
670
 
 
671
 
 
672
/* n_29.t:  #undef directive.   */
 
673
 
 
674
/* 29.1:    Undefined macro is not a macro. */
 
675
/*  DEFINED;    */
 
676
#define DEFINED
 
677
#undef  DEFINED
 
678
    DEFINED;
 
679
 
 
680
/* 29.2:    Undefining undefined name is not an error.  */
 
681
#undef  UNDEFINED
 
682
 
 
683
 
 
684
/* n_30.t:  Macro call. */
 
685
/*  Note:   Comma separate the arguments of function-like macro call,
 
686
        but comma between matching inner parenthesis doesn't.  This feature
 
687
        is tested on so many places in this suite especially on *.c samples
 
688
        which use assert() macro, that no separete item to test this feature
 
689
        is provided.    */
 
690
 
 
691
/* 30.1:    A macro call may cross the lines.   */
 
692
#undef  FUNC
 
693
#define FUNC( a, b, c)      a + b + c
 
694
/*  a + b + c;  */
 
695
    FUNC
 
696
    (
 
697
        a,
 
698
        b,
 
699
        c
 
700
    )
 
701
    ;
 
702
 
 
703
 
 
704
/* n_32.t:  Escape sequence in character constant in #if expression.    */
 
705
 
 
706
/* 32.1:    Character octal escape sequence.    */
 
707
#if     '\123' != 83
 
708
    Bad evaluation of octal escape sequence.
 
709
#endif
 
710
 
 
711
/* 32.2:    Character hexadecimal escape sequence.  */
 
712
#if     '\x1b' != '\033'
 
713
    Bad evaluation of hexadecimal escape sequence.
 
714
#endif
 
715
 
 
716
 
 
717
/* n_37.t:  Translation limits. */
 
718
 
 
719
/* 37.1:    Number of parameters in macro: at least 31. */
 
720
#define glue31(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E)   \
 
721
    a##b##c##d##e##f##g##h##i##j##k##l##m##n##o##p##q##r##s##t##u##v##w##x##y##z##A##B##C##D##E
 
722
 
 
723
/* 37.2:    Number of arguments of macro call: at least 31. */
 
724
/*  ABCDEFGHIJKLMNOPQRSTUVWXYZabcde;    */
 
725
    glue31( A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R
 
726
            , S, T, U, V, W, X, Y, Z, a, b, c, d, e);
 
727
 
 
728
/* 37.3:    Significant initial characters in an internal identifier or a
 
729
        macro name: at least 31.  */
 
730
/*  ABCDEFGHIJKLMNOPQRSTUVWXYZabcd_;    */
 
731
    ABCDEFGHIJKLMNOPQRSTUVWXYZabcd_;
 
732
 
 
733
/* 37.4:    Nested conditional inclusion: at least 8 levels.    */
 
734
/*  nest = 8;   */
 
735
#ifdef  A
 
736
#else
 
737
#   ifdef   B
 
738
#   else
 
739
#       ifdef   C
 
740
#       else
 
741
#           ifdef   D
 
742
#           else
 
743
#               ifdef   E
 
744
#               else
 
745
#                   ifdef   F
 
746
#                   else
 
747
#                       ifdef   G
 
748
#                       else
 
749
#                           ifdef   H
 
750
#                           else
 
751
                                nest = 8;
 
752
#                           endif
 
753
#                       endif
 
754
#                   endif
 
755
#               endif
 
756
#           endif
 
757
#       endif
 
758
#   endif
 
759
#endif
 
760
 
 
761
/* 37.5:    Nested source file inclusion: at least 8 levels.    */
 
762
/*  nest = 1;  nest = 2;  nest = 3;  nest = 4;
 
763
    nest = 5;  nest = 6;  nest = 7;  nest = 8;  */
 
764
#define     X8
 
765
#include    "nest1.h"
 
766
 
 
767
/* 37.6:    Parenthesized expression: at least 32 levels.   */
 
768
/*  nest = 32;  */
 
769
#if     0 + (1 - (2 + (3 - (4 + (5 - (6 + (7 - (8 + (9 - (10 + (11 - (12 +  \
 
770
        (13 - (14 + (15 - (16 + (17 - (18 + (19 - (20 + (21 - (22 + (23 -   \
 
771
        (24 + (25 - (26 + (27 - (28 + (29 - (30 + (31 - (32 + 0))))))))))   \
 
772
        )))))))))))))))))))))) == 0
 
773
    nest = 32;
 
774
#endif
 
775
 
 
776
/* 37.7:    Characters in a string (after concatenation): at least 509. */
 
777
"123456789012345678901234567890123456789012345678901234567890123456789\
 
778
0123456789012345678901234567890123456789012345678901234567890123456789\
 
779
0123456789012345678901234567890123456789012345678901234567890123456789\
 
780
0123456789012345678901234567890123456789012345678901234567890123456789\
 
781
0123456789012345678901234567890123456789012345678901234567890123456789\
 
782
0123456789012345678901234567890123456789012345678901234567890123456789\
 
783
0123456789012345678901234567890123456789012345678901234567890123456789\
 
784
012345678901234567"
 
785
        ;
 
786
 
 
787
/* 37.8:    Characters in a logical source line: at least 509.  */
 
788
    int a123456789012345678901234567890 = 123450;   \
 
789
    int b123456789012345678901234567890 = 123451;   \
 
790
    int c123456789012345678901234567890 = 123452;   \
 
791
    int d123456789012345678901234567890 = 123453;   \
 
792
    int e123456789012345678901234567890 = 123454;   \
 
793
    int f123456789012345678901234567890 = 123455;   \
 
794
    int A123456789012345678901234567890 = 123456;   \
 
795
    int B123456789012345678901234567890 = 123457;   \
 
796
    int C123456789012345678901234567890 = 123458;   \
 
797
    int D1234567890123456789012 = 123459;
 
798
 
 
799
/* 37.9:    Macro definitions: at least 1024.   */
 
800
 
 
801
#define X0400
 
802
#include    "m4095.h"
 
803
/*  0x0400; */
 
804
    BNJ;
 
805