view test/inline.c @ 542:492f06738550

working... (struct init fix)
author kono
date Sun, 01 Jan 2006 18:49:07 +0900
parents 0f24e1dba811
children 74bbea56b8e5
line wrap: on
line source

const int a = 5,b = -3;
int kkkk = 333;
static const int as = 5,bs = -3;
const char hoo[] = "test";
char hoo0[] = "test";
static const char haa[] = "test";
static inline const int f(int k);

volatile const int i = 3;

extern int printf(char *,...);
int
main0()
{
    volatile const int j = 3;
    switch(i) {
    case 1: printf("#0016:1\n"); break;
    case 2: printf("#0017:2\n"); break;
    case 3: printf("#0018:3\n"); break;
    case 4: printf("#0019:4\n"); break;
    }
    switch(j) {
    case 1: printf("#0022:1\n"); break;
    case 2: printf("#0023:2\n"); break;
    case 3: printf("#0024:3\n"); break;
    case 4: printf("#0025:4\n"); break;
    }
    return 0;
}


extern int printf(char *,...);

static inline const int f(int k)
{
    return k+1;
}

inline int in1(int i,int j)
{
   if (i>j) return j;
   else return i;
}

static
inline int ins(int i,int j)
{
   printf("#0047:%d %d\n",i,j);
   if (f(i)>j) return j;
   else return i;
}

static
inline int ins1(int i,int j, int k)
{
   printf("#0055:%d %d %d\n",i,j,k);
   if (f(i)>j) return j;
   else return i;
}

inline __attribute__((always_inline)) int in2(int p,int i,int j)
{
    int k = -20,m;
    do {
	k += 3;
    } while ( k < j);
    printf("#0066: %d do %d\n",p,k);

    while (k > j) {
	k -= 3;
    } 
    printf("#0071: %d while %d\n",p,k);

    m = 0;
    for(k=0;k<j;k++) {
	m += k;
    }
    printf("#0077: %d for %d\n",p,m);

    switch(i) {
    case 1: k = 1;
	break;
    case 2: k = 2;
	break;
    case 3: k = 3;
	break;
    case 4: k = 4;
	break;
    default: k = 5;
    }
    printf("#0090: %d switch %d\n",p,k);

    for(k=0;k<j;k++) {
	i += k;
	if (k<3) continue;
    }
    printf("#0096: %d for %d\n",p,i);
    goto hoge;
hage:
    goto hage;
hoge:
    return 0;

}

int (*fnp)(int i,int j,int k);

int (*fnp3)(int i,int j,int k);

void
a0(int k,int j)
{
    int k1,j1;
    const int v=3,x=6;
    // a = 10;

    k1 = in1(a,b);
    printf("#0117:%d %d %d\n",a,b,k1);
    j1 = in1(k,j-6)+f(k1);
    printf("#0119:%d %d %s\n",k1,j1,hoo);
    k1 = &v-&x>0? &v-&x : &x-&v;
    printf("#0121:v-x: %d\n",k1);

    k1 = ins(a,b);
    j1 = ins(k,j-6)+f(k1);
    printf("#0125:%d %d %s\n",k1,j1,haa);

    k1 = ins(as,bs);
    j1 = ins(k,j-6)+f(k1);
    printf("#0129:%d %d %s\n",k1,j1,haa);

    k1 = ins(v,x);
    j1 = ins(k,j-6)+f(v);
    printf("#0133:%d %d %s\n",k1,j1,haa);

    k1 = fnp(v,x,5);
    j1 = ins1(k,j-6,6)+f(v);
    printf("#0137:%d %d %s\n",k1,j1,haa);
}

void
a1(int k,int j)
{
    in2(1,k,j);
    in2(2,3,10);
    in2(3,k,10);
    in2(4,2,j);
    in2(5,2,1);
    in2(6,0,2);
    in2(8,j*3,in2(7,k+3,10-j));
    fnp3(9,0,2);
}

static
inline int order(int a0,int a1,int a2, int a3, int a4)
{
    printf("#0156:order  %d %d %d %d %d\n",a0,a1,a2,a3,a4);
}

static
inline int order1(int a0,int a1,int a2, int a3, int a4)
{
    printf("#0162:orderp %d %d %d %d %d\n",a0,a1,a2,a3,a4);
}

int (*order1p)(int a0,int a1,int a2, int a3, int a4) = order1;

static inline int inmain(int ac,char *av[])
{
     fnp = ins1;
     order(11,12,13,14,15);
     order1p(11,12,13,14,15);
     a0(15,16);
     a0(-19,16);
     fnp3 = in2;
     a1(19,110);
     main0(ac,av);
     return 0;
}


int
main(int ac,char *av[])
{
     fnp = ins1;
     order(1,2,3,4,5);
     order1p(1,2,3,4,5);
     a0(5,6);
     a0(-9,6);
     fnp3 = in2;
     a1(9,10);
     main0(ac,av);
     inmain(ac,av);
     return 0;
}