c - Funtion pointer to function returning pointer to said function type -
for implementation of finite state machine, achieve this:
currentfunction = currentfunction(int arg);
with currentfunction
being function pointer function returns function pointer of same function type.
is possible in c? how?
first of all, need obscure things always originate muddy program design. trying solve problem x, , think method y it. ask how y working, though not correct solution begin with. root of problem might x incorrectly designed.
that being said, can using struct wrapper , thereby taking advantage of incomplete struct types:
typedef struct func_wrapper_t { struct func_wrapper_t (*func) (int); } func_t; ... func_t some_function (int x) { ... return (func_t){ some_function }; } ... int main(void) { func_t f = some_function(0); return 0; }
Comments
Post a Comment