假设我们有一个事件(int)和动作(函数指针)的列表,如:
typedef struct action_type {
int event;
int (*func)();
} action_type;
action_type actions[] = {
{ my_event1, my_action1 },
{ my_event2, my_action2 },
{ my_event3, my_action3 },
{ my_event4, my_action1 }
}
并且我想为表的一部分实际运行该操作添加条件,>]
action_type actions[] = { { my_event1, exceeds(&temperature, 100) , my_action1 }, { my_event1, between(&temperature, 50, 80), my_action2 }, ... }
有没有办法得到这样的符号?
或者我是否需要创建类似的内容:
action_type actions[] = { { my_event1, $temperature, exceeds, 100, my_action1 }, ... }
但是,这种方法只允许使用固定类型的固定数量的参数。当我编写库时,条件可能几乎是什么,我正在寻找一种方法,以允许对condition()函数使用不同的变量类型和不同的参数计数。
编辑:添加了有关参数数量和类型可能不同的条件的附加信息。
假设有事件(int)和动作(函数指针)的列表,如:typedef struct action_type {int event; int(* func)(); } action_type; action_type actions [] = {{my_event1,...
我会使用X_MACRO,即:类似这样的东西:
您可以做这样的事情