If you want bar
to return foo
, then you have to change the return type of bar
so that it returns a function that takes void and returns void
instead of just void
:
static (void (*)(void)) bar(void) {
return foo;
}
Also, that first example shouldn't work either.
Edit based on your edit: you can't (shouldn't) return
any data from a void
function. void
is the absence of data. In C, you can only return;
from a function that is declared as returning void
-- you can't return <data>;
from it.
So foo()
does not give you any data. It can only be used as a statement, not as an expression.
return foo();
therefore does not make sense in two ways: the first is that bar
may not return anything as it is declared to return void
, and the second is that even if bar
does return an actual data type, foo()
is still of type void
and you cannot return
that.
The first example works because both foo
and bar
return int16_t
s, which are actual data.