承接上一篇 优化的套路再此


#include<stdio.h>
#include <string.h>
typedef unsigned char  uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int   uint32_t;
uint8_t fun1(char * p)
{
    printf("%s\n", p);
    return 1;
}

uint8_t fun2(char * p)
{
    printf("%s\n", p);
    return 1;
}

uint8_t fun3(char * p)
{
    printf("%s\n", p);
    return 1;
}

int main()
{

	char *t1=(char *)"fun1";
	char *t2=(char *)"fun2";
	char *t3=(char *)"fun3";
	#if 0
	fun1(t1);
	fun2(t2);
	fun3(t3);
	#else

    uint8_t funarr[3]={2,1,0},i;
    uint8_t (*pf[3])(char * p);
    pf[0] = fun1; 
    pf[1] = &fun2; 
    pf[2] = &fun3;//优化:这里的赋值 最好写成一个整体
    for(i=0;i<3;i++)//已经优化:这里i已经换成了数组啦 随便点菜
        pf[funarr[i]](t1);//优化:这里最好不要传入参数了 函数写void的!!

   	#endif

    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42381351/article/details/85229135