File: n_26.c

package info (click to toggle)
mcpp 2.7.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,024 kB
  • ctags: 29,151
  • sloc: ansic: 35,191; sh: 9,231; makefile: 176; cpp: 84; exp: 18
file content (56 lines) | stat: -rw-r--r-- 1,049 bytes parent folder | download | duplicates (8)
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
52
53
54
55
56
/* n_26.c:  The name once replaced is not furthur replaced. */

#include    "defs.h"

int     f( a)
    int     a;
{
    return  a;
}

int     g( a)
    int     a;
{
    return  a * 2;
}

main( void)
{
    int     x = 1;
    int     AB = 1;
    int     Z[1];

    fputs( "started\n", stderr);

    Z[0] = 1;

/* 26.1:    Directly recursive object-like macro definition.    */
/*  Z[0];   */
#define Z   Z[0]
    assert( Z == 1);

/* 26.2:    Intermediately recursive object-like macro definition.  */
/*  AB; */
#define AB  BA
#define BA  AB
    assert( AB == 1);

/* 26.3:    Directly recursive function-like macro definition.  */
/*  x + f(x);   */
#define f(a)    a + f(a)
    assert( f( x) == 2);

/* 26.4:    Intermediately recursive function-like macro definition.    */
/*  x + x + g( x);  */
#define g(a)    a + h( a)
#define h(a)    a + g( a)
    assert( g( x) == 4);

/* 26.5:    Rescanning encounters the non-replaced macro name.  */
/*  Z[0] + f( Z[0]);    */
    assert( f( Z) == 2);

    fputs( "success\n", stderr);
    return  0;
}