Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C语言中的事件管理 如何在C中实现事件侦听器机制,我熟悉C++和java。我发现用C语言没有什么好方法,最好是用函数指针。提前感谢。_C_Function Pointers_Event Listener - Fatal编程技术网

C语言中的事件管理 如何在C中实现事件侦听器机制,我熟悉C++和java。我发现用C语言没有什么好方法,最好是用函数指针。提前感谢。

C语言中的事件管理 如何在C中实现事件侦听器机制,我熟悉C++和java。我发现用C语言没有什么好方法,最好是用函数指针。提前感谢。,c,function-pointers,event-listener,C,Function Pointers,Event Listener,通常,一个好方法是在传入事件和回调函数(函数指针)之间建立映射:例如: static const event_handling_map_t event_handling_map[] = { {EVENT1, handle_event_1}, {EVENT2, handle_event_2}, {EVENT3, handle_event_3} } event_handling_map[EVENT1

通常,一个好方法是在传入事件和回调函数(函数指针)之间建立映射:例如:

static const event_handling_map_t event_handling_map[] = {
      {EVENT1,           handle_event_1},
      {EVENT2,           handle_event_2},
      {EVENT3,           handle_event_3}
  }
event_handling_map[EVENT1].handle_events_cb(args);
其中handle_事件是应处理特定事件的函数。 因此,当接收到事件时,可以使用特定的函数,例如(假设EVENT1在枚举中定义,且其值为0),该函数的调用方式如下:

static const event_handling_map_t event_handling_map[] = {
      {EVENT1,           handle_event_1},
      {EVENT2,           handle_event_2},
      {EVENT3,           handle_event_3}
  }
event_handling_map[EVENT1].handle_events_cb(args);

在这种情况下,
handle\u event\u cb
将是
handle\u event\u 1

用于自己实现通用事件处理系统?一些特定的事件处理系统?一些特殊类型的活动?到目前为止你试过什么?哪些有效,哪些无效?