回调函数设计

##回调函数——宏定义使用
#include <stdio.h>
#include <stdlib.h>

typedef struct ase_msg ase_msg_t;
struct ase_msg
{
    int num;
    float high;
    int age;
};

// typedef int(*func_cb)(int a, int b) func_cb_t; --error use
// 使用宏定义定义回调函数形式
#define CB(func_b)  int(*func_b)(int a, int b)

typedef struct cb_test
{
    int a;
    int b;
    int (*fun_cb)(int a, int b);
    CB(fun_cb_2);
}cb_test_t;
int Add_num(int a, int b){//cb_1
    return a + b;
}
int Num_add(int a, int b){//cb_2
    return a + b + 10;
}

int main(){
    cb_test_t ts;
    ase_msg_t ase;
    ts.a = 10;
    ase.num = 1;
    ase.high = 0.25;
    ase.age = 17;
    ts.b = 20;
    ts.fun_cb = Add_num;//赋值回调函数
    ts.fun_cb_2 = Num_add;
    int c = 0;
    c = ts.fun_cb(ts.a, ts.b);
    ase.num = ts.fun_cb_2(ts.a, ts.b);
    printf("cb->[%d]\n", c);
    printf("ase.num =[%d],ase.high=[%f]ase.age=[%d]\n", ase.num, ase.high, ase.age);
    return 0;
}