Error Invalid use of void expression

后端 未结 3 1307
夕颜
夕颜 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:01

    I'm not sure how the code in (1) can possibly compile. But here is what you should be using:

    int rt_task_start (RT_TASK *task, void(*task_func)(void *arg), void *arg);
    int val = 1;
    rt_task_start(&demo_task1, demo, &val);
    

    You cannot pass the function pointer bound to a specific argument, that is something like a closure, which isn't available in C. You can, however, pass the function pointer and then separately pass the argument you want to apply (which is what the function signature suggests you should do). But you must pass that argument as a pointer, not a literal.

提交回复
热议问题