OSDN Git Service

* gcc.dg/cpp/defined_trad.c: New test.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / cpp / macro3.c
1 /* { dg-do run } */
2 /* { dg-options "-std=c99" } */
3
4 /* First two tests sourced from a bug report of Thomas Pornin.
5    Varargs test source Jamie Lokier.
6    All adapted for the testsuite by Neil Booth, Oct 2000.  */
7
8 int c(int x)
9 {
10   return x;
11 }
12
13 int a(int x)
14 {
15   return x;
16 }
17
18 /* Tests various macro abuse is correctly expanded.  */
19 #define c(x) d
20 #define d(x) c(2)
21
22 /* Every GCC <= 2.96 appears to fail this.  */
23 #define a(x) b(
24 #define b(x) a(
25
26 #define apply(...)   apply2 (__VA_ARGS__)  
27 #define half(x)      ((x) / 2)
28 #define apply2(f,x)  f (x)
29
30 extern void abort (void);
31 extern void exit (int);
32
33 int main()
34 {
35   /* Expands to c(2).  */
36   if (c(c)(c) != 2)
37     abort ();
38
39   /* Expands to a(2).  */
40   if (a(a)x)2) != 2)
41     abort ();
42
43   if (apply (half, 200) != 100)
44     abort ();
45
46   exit (0);
47 }