1 Star 0 Fork 0

hemars/lab_c

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
func_ptr.c 708 Bytes
一键复制 编辑 原始数据 按行查看 历史
hemars 提交于 2024-12-30 22:44 +08:00 . init
#include <stdio.h>
void call_back_func0() { printf("callback function 0 called\n"); }
void call_back_func1() { printf("callback function 1 called\n"); }
void call_back_func2() { printf("callback function 2 called\n"); }
void call_back_func3() { printf("callback function 3 called\n"); }
enum event_type { EVENT0 = 0, EVENT1, EVENT2, EVENT3, EVENT_MAX };
void (*func[])(void) = {
call_back_func0,
call_back_func1,
call_back_func2,
call_back_func3,
};
void handle_event(int event_type, void (*callback)(void)) {
printf("event %d occured\n", event_type);
if (callback) {
callback();
}
}
void func_ptr_demo() {
for (int idx = 0; idx < EVENT_MAX; idx++) {
func[idx]();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hemars/lab_c.git
git@gitee.com:hemars/lab_c.git
hemars
lab_c
lab_c
master

搜索帮助