Can I write a recursive type definition ?

From: Timothy Madden (batman_at_rmv.spam.home.ro)
Date: 09/30/04


Date: Thu, 30 Sep 2004 17:26:51 +0200


[Cross-posted to: comp.lang.c, comp.lang.c++]

Hello all

I'm facing a very strange problem. I need to define a function that takes as
argument something like a pointer to itself. It takes as argument a pointer
of the same type as a pointer to itself and with possibly other
pointer-to-function value. But I don't have a data type for such a pointer
because the function prototype is in the same time being defined. I hope you
are following me ...

Actualy I need to define a pointer to a function. Different modules of my
app will install a new function to be pointed by this pointer, and each new
function will remember the address of and call the previous function,
forming a chain that exists only in code. I guess the idea is used for
at_exit() function in the library or something like it.

Now I want the function to take as argument a pointer to another instance of
the same function type. This will allow for removing functions from the
chain even in a different order than the one functions were installed, by
having each installed function recognize it's own address in the argument
and then return as a result the previous installed function that it knows of

I hope you are following me...

So how could I declare the prototype for a function that takes as argument
and that returns a pointer to the same function type being declared ?

Thank you
Timothy Madden
Romania
--------------------------------------------------
And I don't wanna miss a thing



Relevant Pages

  • Re: dereferencing function pointer types
    ... typedef int; ... Dereferencing a function pointer does nothing. ... & (function type expression) ...
    (comp.lang.c)
  • Re: function pointers as function parameters
    ... That's the size of a pointer. ... The * operator always converts the function type expression ... The second one has no conversions. ...
    (comp.lang.c)
  • Re: some pointer issues....
    ... The only two times when an expression of function type is not ... automatically converted to a pointer, ... Since sizeof is not defined for expressions of function type, ... pete would you like to explain by giving an example? ...
    (comp.lang.c)
  • Re: function pointers as function parameters
    ... > The * operator always converts the function type expression ... > to a pointer, ... the * operator doesn't do any conversions. ... The * operator expects a pointer operand; ...
    (comp.lang.c)
  • Re: Can I write a recursive type definition ?
    ... > argument something like a pointer to itself. ... > having each installed function recognize it's own address in the argument ... > So how could I declare the prototype for a function that takes as argument ... > and that returns a pointer to the same function type being declared? ...
    (comp.lang.c)