Error Invalid use of void expression

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

    void (*task_func)(void *arg);
    

    The above statement defines task_func to be a pointer to a function which takes a pointer of type void * and returns no value.

    Therefore, when you call your function rt_task_start, you should pass a pointer to a function as the second argument. Also, you should pass a pointer of type void * as the third argument, not an integer. A function name evaluates to a pointer to the function, so you can simply pass the function name as the argument value, or you can use the address-of operator & before the function name.

    int arg = 4;
    
    // both calls are equivalent
    
    rt_task_start(&demo_task1, demo, &arg);
    rt_task_start(&demo_task1, &demo, &arg);
    

提交回复
热议问题