Error Invalid use of void expression

后端 未结 3 1309
夕颜
夕颜 2021-01-02 01:54

I have a function int rt_task_start (RT_TASK *task, void(*task_func)(void *arg), void *arg) where in second argument i am passing a function with argument.

3条回答
  •  不知归路
    2021-01-02 02:08

    Surely you want:

      int i=1;
      rt_task_start(&demo_task1, demo, (void*) &i);
    

    Just by matching the argument types, remember the second argument is just a function pointer, not a function call with its own argument, it's own argument is only used when you call it within rt_task_demo. If you then want to use the value '1' in function 'rt_task_demo' you would recast it like

    int ii = *(int*) arg;
    

提交回复
热议问题