我想在FSM中实现带有参数的函数。 当我尝试此操作时,会出现此错误
rollapply
代码如下:
dates_v <- seq(as_date("2018-01-01"), as_date("2018-09-14"), by = "days")
df <- data.frame(dates = rep(dates_v,sample(seq(9000,11000), length(dates_v), replace = TRUE))) %>%
mutate(values = rnorm(length(dates)))
答案 0 :(得分:1)
初始化函数的指针时不能设置参数,该参数应声明为struct
的另一个成员
typedef struct {
void (*fun)(unsigned long);
unsigned long out;
unsigned long delay;
unsigned long Next_State[4];
} state ;
state fsm[4] = {
{DriveCenter,86,50,{stop,right,left,stop}},
{DriveRight,45,50,{stop,right,left,stop}},
{DriveLeft,787,50,{stop,right,left,stop}},
{DriveStop,33,50,{stop,right,left,stop}}
};
在C11下,您可以使用匿名struct
来说明这两个变量可以协同工作:
typedef struct {
struct {
void (*fun)(unsigned long);
unsigned long out;
};
unsigned long delay;
unsigned long Next_State[4];
} state ;
state fsm[4] = {
{{DriveCenter,86},50,{stop,right,left,stop}},
{{DriveRight,45},50,{stop,right,left,stop}},
{{DriveLeft,787},50,{stop,right,left,stop}},
{{DriveStop,33},50,{stop,right,left,stop}}
};