/* ---------------------------------------------------------------------- */ @start A // #include "example-incl.cc" // neco B @compare A I B @stop /* ---------------------------------------------------------------------- */ @start A @compare A @stop @start #define A a A @compare a @stop @start A @compare a @stop @clear @start A @compare A @stop /* ---------------------------------------------------------------------- */ @clear @start #define A(x)x*x A(a) @compare a*a @stop @start #define A(x,y) x*y A(a,b) @compare a*b @stop #if 0 @start #define A(x) x x A(a) @compare a a @stop @start #define A(x) x x A (A (a)) @compare a a a a @stop #endif @start #define A(x,y) {x,y} #define B(u,v) [A(u,v)] A(1,2); B(1,2); @compare {1,2}; [{1,2}]; @stop @clear @start #define F(x,y) x*y F(int,c) F ( char, d ) F (bool,e) F(char*,f); @compare int*c char*d bool*e char**f; @stop /* ---------------------------------------------------------------------- */ @start #define A a #define B b #define AB z #define C A##B #define D A##b C D @compare z Ab @stop @clear /* ---------------------------------------------------------------------- */ @clear @start #define Mi micro #define Ni nothing #define MiNi small #define Q Mi##Ni #define Q2 Mi##Ni##Mum int*Mi; int*Ni; float*Q; double*Q2; @compare int*micro; int*nothing; float*small; double*MiNiMum; @stop /* ---------------------------------------------------------------------- */ @clear @start #define AB printf("works\n") #define C(a,b) a##b #define D C(A,B) D; @compare printf("works\n"); @stop /* ---------------------------------------------------------------------- */ /* cpp.pdf */ @clear @start #define NUMBERS 1, \ 2, \ 3 int x[] = { NUMBERS }; @compare int x[] = { 1, 2, 3 }; @stop @clear @start #define TABLESIZE BUFSIZE #define BUFSIZE 1024 TABLESIZE @compare 1024 @stop @clear @start #define neco() nic neco neco() @compare neco nic @stop @clear @start #define lang_init() c_init() lang_init() @compare c_init() @stop @clear @start #define lang_init () c_init() lang_init() @compare () c_init()() @stop @clear @start #define min(X, Y) ((X) < (Y) ? (X) : (Y)) x = min(a, b); @compare x = ((a) < (b) ? (a) : (b)); @stop @start min (min (a, b), c) @compare ((((a) < (b) ? (a) : (b))) < (c) ? (((a) < (b) ? (a) : (b))) : (c)) @stop @start min (,) @compare (() < () ? () : ()) @stop @start min ((,),) @compare (((,)) < () ? ((,)) : ()) @stop @start #define foo(x) x, "x" foo(bar) @compare bar, "x" @stop @clear @start #define xstr(s) str(s) #define str(s) #s #define foo 4 str (foo) @compare "foo" @stop @start xstr (foo) @compare "4" @stop @start #define eprintf(...) fprintf (stderr, __VA_ARGS__) eprintf ("%s:%d: ", input_file, lineno) @compare fprintf (stderr, "%s:%d: ", input_file, lineno) @stop #if 0 @clear @start #define eprintf(format, ...) fprintf (stderr, format, ##__VA_ARGS__) eprintf ("success!\n") @compare fprintf(stderr, "success!\n"); @stop #endif @clear @start #define AFTERX(x) X_ ## x #define XAFTERX(x) AFTERX(x) #define TABLESIZE 1024 #define BUFSIZE TABLESIZE AFTERX(BUFSIZE) @compare X_BUFSIZE @stop @start XAFTERX(BUFSIZE) @compare X_1024 @stop #if 0 @clear @start #define foo a,b #define bar(x) lose(x) #define lose(x) (1 + (x)) bar(foo) @compare (1 + (a,b)) @stop #endif @clear @start #define ignore_second_arg(a,b,c) a; c ignore_second_arg (foo (), ignored (), something); @compare foo (); something; @stop /* cpp internals */ @clear @start #define foo(x) bar x foo(foo) (2) @compare bar foo (2) @stop /* ---------------------------------------------------------------------- */