Can I declare an opaque function pointer type, without a full prototype, and initialize a structure containing a pointer to a function of that type, without fleshing out the signature (which will be full declared at the point of use).
For example:
// file api.h
typedef void (*function_ptr)(???);
typedef struct {
function_ptr func;
} S;
function_ptr foo;
function_ptr bar;
const S structs[] = { {foo}, {bar} };
// file impl.c
typedef ret_type (*function_ptr)( // complex argument list );
void foo( // complex argument list) {
...
}
void bar( // complex argument list) {
...
}
structs[0].func(arg1, arg2, arg3);
Basically I want to hide the details of the function prototype (the return type and the parameter list) from the api.h
header file, but still declare struct
s that use a pointer to this function. At the location of the declaration of any such functions, or of their use, the full prototype should be in scope, and argument checking will occur, etc.
A similar pattern works fine with forward-declared structs: you could forward declare an opaque struct C
and use pointers to that struct in other structures, including static initialization of pointers to C
eg:
struct C;
typedef struct {
struct C* c;
} D;
extern struct C c;
D d[] = {
{ &c }
};
The details of C
are totally hidden. I'm looking for the equivalent pattern for function pointers.