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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -