Search code examples
cfunction-pointerslibxml2

expected 'void (**)(void *, const char *)' but argument is of type 'void (*)(void *, const char *)


I can't figure out what

void (**)(void *, const char *)
/*    ^^ why are there 2 asterisks here?

means, it's a pointer to a function but I fail to

The exact error message is

expected 'void (**)(void *, const char *)' but argument is of type 'void (*)(void *, const char *)'      
       initGenericErrorDefaultFunc (xmlGenericErrorFunc *handler);      
       ^
/usr/include/libxml2/libxml/xmlerror.h:866:

this is the default error message function in libxml2, the function that I am trying to call is

initGenericErrorDefaultFunc (xmlGenericErrorFunc *handler);

and my handler argument function is

void
skipErrorPrinting(void *ctx, const char *msg, ...)
{
}

then I call initGenericErrorDefaultFunc() like this

initGenericErrorDefaultFunc(skipErrorPrinting);

and here the definition of xmlGenericErrorFunc

typedef void (XMLCDECL *xmlGenericErrorFunc) (void *ctx,
                 const char *msg,
                 ...) LIBXML_ATTR_FORMAT(2,3);

Solution

  • It is pretty wonky, it wants to return the default error handler. So you have to pass a pointer to a variable. Like this (untested):

    xmlGenericErrorFunc handler;
    initGenericErrorDefaultFunc(&handler);
    

    If I understand your intentions properly, this is not the function you actually want to use to suppress errors. Use xmlSetGenericErrorFunc() instead. You can use initGenericErrorDefaultFunc() to restore it again. Pass NULL.