typedef void (*dialog_select_cb_t)(uint16_t type, void *value, uint16_t index);
-
定义一个函数指针变量,这个函数指针的参数是
(uint16_t type, void *value, uint16_t index) -
// 定义一个函数指针变量(无 typedef) void (*select_cb)(uint16_t type, void *value, uint16_t index); select_cb = a_function; //这是变量的赋值 -
无
typedef:定义的是一个变量,语法是void (*变量名)(...);有typedef:定义的是一种类型,语法是typedef void (*类型名)(...); -
int a;——a是变量typedef int a;——a是int的别名,之后可以写a b;定义变量b
void dialog_set_select_cb(dialog_select_cb_t cb);
- 提供一个函数允许其他地方传入一个
dialog_select_cb_t类型的函数
static dialog_select_cb_t select_cb;
void dialog_set_select_cb(dialog_select_cb_t cb)
{
select_cb = cb;
}
- 我们定义了一个回调函数(函数指针)
dialog_select_cb_tselect_cb - 赋值
select_cb = cb之后,当前函数指针指向了传入的函数。 - 调用:
select_cb(now_type, now_value, i);就相当于调用 ↓ 下面传入的函数。
dialog_set_select_cb(unit_select_cb);
static void unit_select_cb(dialog_val_type_t type, void *value, uint16_t index)
{
}