Mercurial > hg > CbC > old > device
view test/tmp8.c @ 367:4efbb07f556b
global variable offset
author | kono |
---|---|
date | Wed, 07 Jul 2004 20:50:07 +0900 |
parents | 84df3dd8cc3d |
children | 0c256ea2a97e |
line wrap: on
line source
#include <alloca.h> int asize = 100; int f(int i,int j,int k,int *l); int g(); int f1(int i,int j,int *l,int k); int g1(int k); void f2(); int main() { int a[0] ; for(asize=4;asize<64000;asize=asize*2+12) { f2(1); f2(0); printf("%d %d\n",g(),f(0,1,2,a)); printf("%d %d\n",g1(100),f1(0,1,a,2)); } return 0; } int g() { int k = 0,i; char *p = alloca(asize<100?100:asize); for(i=0;i<100;i++) p[i]=i; for(i=0;i<100;i++) k += p[i]; return k; } int f(int i,int j,int k,int *l) { *l = 3; if (i++ >20) return *l; return f(i,j,k,(int*)alloca(asize)); } int g1(int k) { int i; char *p = ((char *)alloca(asize>100?asize:100))+k; p -= k; for(i=0;i<100;i++) p[i]=i; for(i=0;i<100;i++) k += p[i]; return k; } int f1(int i,int j,int *l,int k) { // printf("f1 &i=%x &k=%x\n",&i,&k); // printf("f1 i=%d j=%d *l=%0x k=%d\n",i,j,l,k); *l = 3; printf("f1 i=%d j=%d *l=%0x k=%d\n",i,j,*l,k); if (i++ >20) return *l; return f1(i,j,(int*)alloca(asize),k); } void f2(int k) { int *l; if (k==1) l = alloca(asize); else l = 0; printf("f2: %0x %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", // l, 0, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40 ); }