Suppose that I had a function in C that accepted as input two void pointers, *a and *b say, as well as a function (as pointer) that itself accepted two void pointers. For example, the function might have a declaration like
arbitrary_type f(void *a, void *b,
arbitrary_type (*g)(void *, void *))
{
...
}
Let's also suppose that the function only acts via the function 'g' (which could be thought of as a sort of getter or setter for the variables pointed to by 'a' and b'.)
Would that function technically be capable of acting on arbitrary triples (a, b, g)
of pointers of the form type_a *a
, type_b *b
, rtype (\*g)(type_a *, type_b *)
without introducing errors?
Would that function technically be capable of acting on arbitrary triples (a, b, g) of pointers of the form type_a *a, type_b *b, rtype (*g)(type_a *, type_b *)
Yes.
without introducing errors?
Well, that depends on the actual code. Note that void *
pointers remove the ability of the compiler to statically check if types of pointers are correct.
It strongly depends on what interface you are modeling, but you can take one void *
pointer and let the user "bind" two a
b
variables together with a struct.