scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

0202-variadic.c (601B)


      1 #define debug1(...)    test1(__VA_ARGS__)
      2 #define debug2(...)    test2(0, #__VA_ARGS__)
      3 #define debug3(t, ...) ((t==1) ? test1(__VA_ARGS__):test2(__VA_ARGS__))
      4 
      5 int
      6 test1(int x, char *s)
      7 {
      8 	int i;
      9 
     10 	if (x != 3)
     11 		return 0;
     12 	for (i = 0; s[i]; i++) {
     13 		if (s[i] != "test1"[i])
     14 			return 0;
     15 	}
     16 	return 1;
     17 }
     18 
     19 int
     20 test2(int x, char *s)
     21 {
     22 	int i;
     23 
     24 	for (i = 0; s[i]; i++) {
     25 		if (s[i] != "1, 2"[i])
     26 			return 0;
     27 	}
     28 	return 1;
     29 }
     30 
     31 int
     32 main()
     33 {
     34 	if (!debug1(3, "test1"))
     35 		return 1;
     36 	if (!debug2(1, 2))
     37 		return 2;
     38 	if (!debug3(1, 3, "test1"))
     39 		return 3;
     40 	if (!debug3(2, 0, "1, 2"))
     41 		return 4;
     42 
     43 	return 0;
     44 }