Error Invalid use of void expression

I have a function int rt_task_start (RT_TASK *task, void(*task_func)(void *arg), void *arg) where in the second argument I pass a function with an argument.

  • When I only pass the function name, there is no problem at this time. (as expected, it works).rt_task_start(&demo_task1, demo, 1);
  • But when I pass rt_task_start(&demo_task1, demo(&val), 1);, he gives me an error error: invalid use of void expression. The variable val is defined previously.int val = 0;
  • When I call with this rt_task_start(&demo_task1, demo(val), 1);, it shows an error Warning passing argument 1 of 'demo' makes pointer from integer without a cast, then error: invalid use of void expression.
  • int *val; *val = 0; rt_task_start(&demo_task1, demo(&val), 1); it also gives me an error.

I can’t understand what I should pass as a pointer to a void. This gives me an error. Any idea please!

+4
source share
3 answers
void (*task_func)(void *arg);

task_func , void * .

, rt_task_start, . , void * , . , , - & .

int arg = 4;

// both calls are equivalent

rt_task_start(&demo_task1, demo, &arg);
rt_task_start(&demo_task1, &demo, &arg);
+4

, (1) . :

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

, , - , C. , , , , ( , ). , .

0

, :

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

, , - , , , rt_task_demo. '1' 'rt_task_demo',

int ii = *(int*) arg;
0

Source: https://habr.com/ru/post/1534044/


All Articles