Mercurial > hg > CbC > old > device
view test/tmp7.c @ 856:d9dd3e6e7c5f
macro compatibility
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Nov 2011 05:44:49 +0900 |
parents | 9598ecec0af5 |
children | e3de6b70abe9 |
line wrap: on
line source
int printf(const char *format, ...); #ifndef INLINE #define INLINE #endif int k=3; struct aa { int a[100]; } aaa,bbb; struct bb { int b[2]; } aaa1,bbb1; INLINE void tmp(void); INLINE struct aa main0(int); INLINE void main01(int k, struct aa a) { printf("#0015:main01 k=%d,a[0]=%d,a[99]=%d\n",k,a.a[0],a.a[99]); } INLINE struct aa main0(int k) { int i; struct aa ccc; for(i=0;i<100;i++) ccc.a[i]=i; ccc.a[55]=k; return ccc; } INLINE struct aa main3(struct aa arg) { int j=++arg.a[55]; return main0(j); } INLINE void main2(struct aa a1) { /* main2 a1.a[99] 0 */ /* main2 a1.a[55] 0 */ /* main2 a1.a[99] 55 */ /* main2 a1.a[55] 44 */ printf("#0043:main2 a1.a[99] %d\n",a1.a[99]); printf("#0044:main2 a1.a[55] %d\n",a1.a[55]); } INLINE struct bb main5(struct aa a1,struct bb a2) { printf("#0050:main5 a1.a[99] %d\n",a1.a[99]); printf("#0051:main5 a1.a[55] %d\n",a1.a[55]); printf("#0052:main5 a2.b[0] %d\n",a2.b[0]); printf("#0053:main5 a2.b[1] %d\n",a2.b[1]); a2.b[0]=333; a2.b[1]=555; return a2; } INLINE void main6(); INLINE void main1(struct aa a1) { /* main1 a1.a[0] 0 */ /* main1 a1.a[0] 44 */ printf("#0065:main1 a1.a[0] %d\n",a1.a[0]); a1.a[55]=44; if (a1.a[0]) main2(a1); else main2(aaa); } int main(ac,av) int ac; char *av[]; { register int i; register char *p; int j = 3; struct { int b; void (*c)(struct aa); } q = {3,main1},r; struct aa *aap[3]; j = 3; aaa.a[0] = 55; aaa.a[99] = 66; main01(j,aaa); bbb = main0(123); printf("#0091:copied main0 ccc.a[55] %d==123\n",bbb.a[55]); aap[2] = &bbb; *aap[2] = main0(123); printf("#0094:complex copied main0 ccc.a[55] %d==123\n",bbb.a[55]); bbb.a[55]=0; j = main0(123).a[55]; printf("#0097:new main0 ccc.a[55] in temporal copy %d==123\n",j); j = 552; bbb = main3(bbb); printf("#0101:main3 bbb.a[55] in temporal copy %d==552 %d==1\n",j,bbb.a[55]); j = main3(bbb).a[55]; printf("#0103:main3 bbb.a[55] in temporal copy %d==2 %d\n",j,bbb.a[53]); j = main3(bbb).a[53]; printf("#0105:main3 bbb.a[55] in temporal copy %d==53 %d\n",j,bbb.a[53]); printf("#0107:%d==3\n",q.b); /* 3==3 */ r = q; printf("#0110:%d==3\n",r.b); /* 3==3 */ (*r.c)(aaa); printf("#0113:main aaa.a[55] %d\n",aaa.a[55]); /* main aaa.a[55] 123 */ bbb.a[0]=44; aaa = bbb; aaa.a[99]=55; /* core dump? */ (*r.c)(aaa); /* main aaa.a[55] 0 */ printf("#0120:main aaa.a[55] %d\n",aaa.a[55]); p = av[0]; if (!p) return 55; i = p[1]; p = p+i; /* 47 ./a.out */ printf("#0126:%d %s\n",i,p-i+3); aaa1.b[0]=33; aaa1.b[1]=55; bbb1 = main5(aaa,aaa1); printf("#0130:main5-2 %d\n", main5(bbb,bbb1).b[0]); printf("#0132:main5-1 %d\n", main5(bbb,main5(aaa,aaa1)).b[0]); main6(); return 0; } typedef struct { char x,y; } s; s P[15],Q[15]; static void l(s p, s q){ printf("%d %d\n", p.x, p.y); } INLINE void main6() { int j = 0; P[j].x = Q[j].x = 10; P[j].y = Q[j].y = -7; l(P[j],Q[j]); } INLINE void tmp() { }