File: n_27.t

package info (click to toggle)
mcpp 2.7.2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 8,152 kB
  • ctags: 29,136
  • sloc: ansic: 35,238; sh: 9,241; makefile: 176; cpp: 84; exp: 18
file content (51 lines) | stat: -rw-r--r-- 1,527 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* n_27.t:  Rescanning of a macro replace any macro call in the replacement
        text after substitution of parameters by pre-expanded-arguments.  This
        re-examination may involve the succeding sequences from the source
        file (what a queer thing!). */

/* 27.1:    Cascaded use of object-like macros. */
/*  1 + 2 + 3 + 4 + 5 + 6 + 7 + 8;  */
#define NEST8   NEST7 + 8
#define NEST7   NEST6 + 7
#define NEST6   NEST5 + 6
#define NEST5   NEST4 + 5
#define NEST4   NEST3 + 4
#define NEST3   NEST2 + 3
#define NEST2   NEST1 + 2
#define NEST1   1
    NEST8;

/* 27.2:    Cascaded use of function-like macros.   */
/*  (1) + (1 + 2) + 1 + 2 + 1 + 2 + 3 + 1 + 2 + 3 + 4;  */
#define FUNC4( a, b)    FUNC3( a, b) + NEST4
#define FUNC3( a, b)    FUNC2( a, b) + NEST3
#define FUNC2( a, b)    FUNC1( a, b) + NEST2
#define FUNC1( a, b)    (a) + (b)
    FUNC4( NEST1, NEST2);

/* 27.3:    An identifier generated by ## operator is subject to expansion. */
/*  1;  */
#define glue( a, b)     a ## b
#define MACRO_1         1
    glue( MACRO_, 1);

#define sub( x, y)      (x - y)
#define head            sub(
#define math( op, a, b) op( (a), (b))

/* 27.4:    'sub' as an argument of math() is not pre-expanded, since '(' is
        missing.    */
/*  ((a) - (b));    */
    math( sub, a, b);

/* 27.5:    Queer thing.    */
/*  (a - b);    */
    head a,b );

/* 27.6:    Recursive macro (the 2nd 'm' is expanded to 'n' since it is in
        source file).   */
/*  n;  */
#define m       n
#define n( a)   a 
    m( m);