为了降低函数的圈复杂度,可以通过查表来调用函数:
#include <stdio.h>
#if 1
typedef int (*pfCallBack)();
int test1()
{
int i = 0;
i++;
printf("%d",i);
return 1;
}
int test2()
{
int i = 1;
i++;
printf("%d",i);
return 1;
}
int test3()
{
int i = 2;
i++;
printf("%d",i);
return 1;
}
int main()
{
pfCallBack table[]={test1,test2,test3};
table[0]();
return 1;
}
#endif
#include <stdio.h>
#if 1
typedef int (*pfCallBack)();
int test1()
{
int i = 0;
i++;
printf("%d",i);
return 1;
}
int test2()
{
int i = 1;
i++;
printf("%d",i);
return 1;
}
int test3()
{
int i = 2;
i++;
printf("%d",i);
return 1;
}
int main()
{
pfCallBack table[]={test1,test2,test3};
table[0]();
return 1;
}
#endif