view test/tmp8.c @ 874:3454953b3df0

fix inline strinit not yet worked.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 01 Apr 2014 23:25:05 +0900
parents c2c709727221
children 5313ed059cee
line wrap: on
line source

int printf(const char *format, ...);

#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[1] ;
   for(asize=4;asize<64000;asize=asize*2+12) {
       f2(1);
       f2(0);
       printf("#0019:%d %d\n",g(),f(0,1,2,a));
       printf("#0020:%d %d\n",g1(100),f1(0,1,a,2));
    }
   return 0; 
}

int
g()
{
   int k = 0,i;

   char *q = alloca(100);
   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];
   for(i=0;i<100;i++) q[i]=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("#0061:f1 &i=%x &k=%x\n",&i,&k);
    // printf("#0062:f1 i=%d j=%d *l=%0x k=%d\n",i,j,l,k);
    *l = 3;
    printf("#0064: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("#0077: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
   );
}