view test/call.c @ 492:cc1a5f764782

*** empty log message ***
author kono
date Wed, 21 Dec 2005 12:10:43 +0900
parents a379da780856
children 10c8eaf0f73b
line wrap: on
line source

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


int
a0(int i);

int (*conv)(int);

int
a0(int i)
{
    return i+3;
}

int
a1(int i)
{
    return i-3;
}


int
a2(int i,int conv(int))
{
    return conv(i);
}

int
a3(int i,int (*conv)(int))
{
    return conv(i);
}

int
a4(int i,int conv(int))
{
    return (*conv)(i);
}

static 
int a5(int i,int (*conv)(int))
{
    return (*conv)(i);
}

typedef int (*fptr)(int,int (*)(int));

unsigned long addrs[]={
     (unsigned long)&a0,
     (unsigned long)&a5,
     (unsigned long)a0,
     (unsigned long)a5,
     0,
};

fptr faddrs[]={
     &a2,
     &a5,
     a2,
     a5,
     0,
};


int
main(int ac,char *av[]) {
    int j,k;
    conv = a0;
    j = conv(3);
    k = a2(4,a1);
    printf("#0070:6 1 = %d %d\n",j,k);
    k = a3(4,a1);
    printf("#0072:6 1 = %d %d\n",j,k);
    k = a4(4,a1);
    printf("#0074:6 1 = %d %d\n",j,k);
    k = a5(4,a1);
    printf("#0076: 1 = %d %d\n",j,k);
    printf("#0077: 1 = %d\n",(unsigned long)a0 == addrs[0]);
    printf("#0078: 1 = %d\n",(unsigned long)a5 == addrs[1]);
    printf("#0079: 1 = %d\n",(unsigned long)a0 == addrs[2]);
    printf("#0080: 1 = %d\n",(unsigned long)a5 == addrs[3]);

    printf("#0082: 1 = %d\n",a2 == faddrs[0]);
    printf("#0083: 1 = %d\n",a5 == faddrs[1]);
    printf("#0084: 1 = %d\n",&a2 == faddrs[2]);
    printf("#0085: 1 = %d\n",&a5 == faddrs[3]);
    return 0;
}