Mercurial > hg > CbC > old > device
view test/macro.c @ 928:96c53f76b360
fix
author | kono |
---|---|
date | Sun, 13 Apr 2014 10:21:40 +0900 |
parents | bd9bd4ba2f1c |
children |
line wrap: on
line source
int printf(const char *format, ...); int heap[100]; #define car(e) (heap[(int)(e)]) #define cadr(e) (heap[((int)(e))+1]) #define TEST int i; TEST char *a = "test" "test"; #define TEST0 33 #define TEST111 TEST0 #define ENDIAN_L 0 #define c(a,b) g(a+1,b+1) #define g(a,b) printf("#0019:%d %d\n",a+1,b+1); #define d(a,b) cadr(b)+3 int stdio0 = 1; int stdio1 = 2; int stdio2 = 3; #define stdio0 stdio0 #define stdio2 stdio1 #define stdio1 stdio2 int recurse(int a,int b) { return a + b + stdio0; } #define recurse(a,b) a+recurse(a,b) /* #define f(a,b) aho+a+b f (a,b) */ int f() { printf("#0045:%d %d %d %d\n",stdio0,stdio1,stdio2, recurse(1,2)); #if ENDIAN_L==0 printf("#0048:ok\n"); #else printf("#0050:bad\n"); #endif return 1 ; } char *init_str = "\ test1\n\ test2\n\ " #ifdef __linux__ // linux case "\ test3 linux\n\ test4\n\ " #ifdef __x86_64__ "__x86_64__\n" #endif #else #ifdef __APPLE__ "\ test3 APPLE\n\ test4\n\ " #endif #ifdef __x86_64__ "__x86_64__\n" #endif #endif ; // name concateneation #define name(a,b) name_##b(a) #define names(a,b) name_ ## b(a) #define names1(x,y) names(x,y) #define hoge 79 #define names2(x) names(x,hoge) #define name_hoge(c) (c+a) #define name_aho(c) (c*a) #define hoge000(a) (a+a) #define aho000(a) (a*a) /* hoge comment */ #define stringify(x) (#x) int main() { int a,b,e; b = heap[TEST111]; d(a,b); a =1; b = 3; #ifndef a c(a, b); /* 3,5 expected */ #endif e=50; heap[51]=3; heap[3]=4; /* 5,4 expected */ #if 0 g(car(cadr(e)),cadr(e)); #endif #if 0 printf("#0086:1\n"); #elif (1) printf("#0088:2\n"); #elif (2) printf("#0090:3\n"); #else printf("#0092:4\n"); #endif #if 0 printf("#0095:1\n"); #elif (0) printf("#0097:2\n"); #elif (0) printf("#0099:3\n"); #else printf("#0101:4\n"); #endif printf("#0103:%d\n",name(3,hoge)); printf("#0104:%d\n",names(3,hoge)); printf("#0105:%d\n",hoge000(3)); printf("#0106:%d\n",names1(4,aho)); printf("#0107:%s\n",stringify(aho)); printf("#0108:%s\n",init_str); printf("#0109:%d\n",names2(4)); printf("#0110:%d\n",name_hoge(names(4,hoge))); /* printf("#0103:%d\n",(3 +a)); printf("#0104:%d\n",(3 +a)); printf("#0105:%d\n",(3 +3)); printf("#0106:%d\n",(4*a)); printf("#0107:%s\n",("aho")); printf("#0108:%s\n",init_str); printf("#0109:%d\n",(4 +a)); */ f(); return 0; } /* For GCC 2.7 and later, we can use specific type-size attributes. */ # define __intN_t(N, MODE) \ typedef int int##N##_t __attribute__ ((__mode__ (MODE))) # define __u_intN_t(N, MODE) \ typedef unsigned int u_int##N##_t __attribute__ ((__mode__ (MODE))) # ifndef __int8_t_defined # define __int8_t_defined __intN_t (8, __QI__); __intN_t (16, __HI__); __intN_t (32, __SI__); __intN_t (64, __DI__); # endif __u_intN_t (8, __QI__); __u_intN_t (16, __HI__); __u_intN_t (32, __SI__); __u_intN_t (64, __DI__); int tmp() #if 0 { return 1; } #else { return 0; } #endif #if 0 #endif /* whoeh wohefwiehfoi */ void longlong(int i,int j) { // long long i,j; if (i>j) main(); }