I have the following recursive type definitions in C and I am wondering how to get it to work:
typedef int (*foo) (bar *);
typedef foo *bar;
The sizes of the pointers are well known so this should be OK.
I somehow need to forward declare bar as some anonymous type that I can then typedef correctly. Not sure how to do this in C since it isn’t a struct
I want to avoid declaring foo as:
typedef int (*foo) (void *)
because then I lose some type checking properties.
There is no forward declaration for
typedefs in C, unfortunately.UPD.
You can create indirectly recursive type as follows:
And then get pointer to function through the field of the argument. But this requires the structure to be allocated somewhere (may be on stack) and additional pointer dereferencing.