c89 - Recursive declaration of function pointer in C -


I want to declare a function that gives an indicator of the same type of function.

I want to use it to implement similar state machines below:

  typedef event_handler_t (* event_handler_t) (event_t *); // compilation error event_handler_t state2 (event_t * e); Event_handler_t state1 (event_t * e) {switch (e-> gt; type) {// ... case SOME_EVENT: return status 2; // ...}} event_handler_t state2 (event_t * e) {switch (e- & gt; type) {// ... case OTHER_EVENT: return state 1; // ...}} // ... event_handler_t event_handler; // ... event_handler (& amp; nbsp;); // ...  

I manage to work around the complexity error using the structures:

  typedef struct event_handler {struct event_handler ( * Func) (Event_t *); } Event_handler_t;  

But this returns the return statement more complex:

  event_handler_t state2 (event_t * e) {{event_handler_t next_handler = {NULL}; Switch (e-> type) {// ... case OTHER_EVENT: next_handler.func = state1; break; // ...} next_handler; }  

I am surprised that there is no better way to create such Function Points in C.

It is not possible to do this in C: a function can not return an indicator back to itself , Because the type of announcement increases again and never ends. For clarification of this page, refer to:

The action described above on the above page means zero (*) () ; Your action is arguably a small downpour.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -