Reading a question in stackoverflow, I wondered whether it's possible to declare a function that takes a pointer to itself. I.e. to make such declaration of foo
, for which the following would be correct:
foo(foo);
The simpliest idea is casting to another function pointer (can't cast to void*
, since it may be smaller), so the function declaration looks like this:
void foo(void (*)());
While that's OK in C (and will work with casting in C++), I wonder, whether it can be done without such hard "reinterpret" casting or losing type information.
In other words, I want the following declaration:
void foo( void (*)( void (*)( void (*) ( ... ))));
but, of course, unlimited declarations are impossible. Naive typedef
ing doesn't help either.
C++ templates are welcome, even if they make the calling code (foo(foo)
) look a bit less succinct, but still finite.
C-style answers that show, how one can drop type information without casting, or other tricks of that sort are, of course, interesting, but won't be accepted.