Perhaps the title isn't clear in itself...
I have a function f (provided by some library) that takes as an argument a function pointer of signature void g(int*)
, i.e.
void f(void (*g)(int*));
However, I would like to use it using a function g
(that I defined) with signature void g(const int*)
. A priori, I can't see how this can violate any const-correctness, as all the signature of f
says is that g
will only ever be called with a (non-const
) int*
(non-const
), and indeed I can call a void (const int*)
function with a non-const
int*
argument.
But GCC complains and says,
expected 'void (*)(int *)', but argument is of type 'void (*)(const int *)'
I can't see how this complaint can be legitimate, so does anyone know whether my understanding of that is wrong, or if there is a way around that?