函数指针的定义:
void (*point_fun)(const char *str);
point_fun先和*结合是指针,()是函数运算符,所以这个指针是指向函数的
#include <stdio.h>
void say_hello(const char *str);
void (*point_say_hello)(const char *str);//point_say_hello先和*结合是指针,()是函数运算符,所以这个指针是指向函数的
typedef void FUN(const char *str); //定义类一个FUN的函数类型
FUN say_typedef;//用上面定义的类型定义,FUN型的变量,相当于声明一个函数。
FUN *point_say_typedef;//用上面定义的类型定义,FUN型的指针,相当于定义一个函数指针。
void (*say_table[2])(const char *str);//根据运算符的先后顺序可知,say_table是个数组;数组的元素是指针,指向函数的指针。
//void (*say_table[2])(const char *str) = {point_say_hello, point_say_typedef};
#define say_interface(a) say_table[a]("lang")//相当于接口
typedef void (*POINT_FUN)(const char *str); //定义类一个POINT_FUN的函数指针类型
POINT_FUN point_fun ;
void main(){
printf("lang start \n");
point_say_hello = say_hello;
point_say_hello("langxw");
point_say_typedef = say_typedef;
point_say_typedef("langxw");
say_table[0] = point_say_hello;
say_table[1] = point_say_typedef;
say_interface(0);
say_interface(1);
point_fun = say_hello;
point_fun("point_fun");
}
void say_hello(const char *str){
printf("hello %s \n", str);
}
void say_typedef(const char *str){
printf("typedef %s \n", str);
}
end