6

I want to define a function type, that returns a pointer to same type of function as itself. I have tried this:

typedef state* (*state)(lex*);

But I get a syntax error as you would guess.

yasar
  • 13,158
  • 28
  • 95
  • 160
  • 3
    You could make it return void * – mike jones Oct 13 '13 at 19:07
  • 2
    Sorry, it's not possible. – Aki Suihkonen Oct 13 '13 at 19:07
  • So the function returns a pointer to a function which returns a pointer to a function which returns.... What is the return type? The return type is the return type. – dyp Oct 13 '13 at 19:09
  • 1
    sounds like it is going to be a hard to read program – AndersK Oct 13 '13 at 19:16
  • @mikejones - No, function pointers and data pointers cannot be used interchangeably. To use `void *` to store a function pointer will result in undefined behaviour when the function is called via the pointer. – detly Oct 13 '13 at 23:21
  • 1
    @detly you can do it in POSIX C. http://stackoverflow.com/questions/12358843/why-are-function-pointers-and-data-pointers-incompatible-in-c-c – mike jones Oct 14 '13 at 01:43
  • Voting to reopen, so that it can be properly deduplicated: this question is a duplicate of [SO 816356](http://stackoverflow.com/questions/816356/how-can-i-typedef-a-function-pointer-that-takes-a-function-of-its-own-type-as-an) (which asks for a solution to this problem), not of [SO 793449](http://stackoverflow.com/questions/793449/recursive-declaration-of-function-pointer-in-c) (which actually answers *this* question, but then asks if a better solution/workaround exists). –  Mar 17 '15 at 09:48

0 Answers0