[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [xml] initGenericErrorDefaultFunc weirdness.



OK, sorry about that - I must be more careful to respond accurately!

Basic C programming example follows:-
---------------------------------------
  bill billsuper work $ cat bb.c
  #include <libxml/xmlerror.h>
  void MyXMLErrorFunction(void *ctx, const char *msg, ...)
  {
    return;
  }

  int main(int argc, char **argv) {
    initGenericErrorDefaultFunc(
      (xmlGenericErrorFunc *)&MyXMLErrorFunction
     );
  return 0;
  }
  bill billsuper work $ gcc -Wall \
    `../xmlinstall/bin/xml2-config --cflags --libs` \
    -o bb bb.c
  bill billsuper work $
-------------------------------------------

The function initGenericErrorDefaultFunc takes a single argument
which is the *address* of a function of type xmlGenericErrorFunc. 
Therefore, since MyXMLErrorFunction is declared as type void, it is
necessary to specify a type override.  The required type is the
address (i.e. a pointer to) a xmlGenericErrorFunc, and in C that is
written as (xmlGenericErrorFunc *).

HTH

Bill


Jose Commins said:
>
> 	With your suggestion below, I get ' main.c:109: error: invalid
> lvalue
> in unary `&' '
> 	With this:
> initGenericErrorDefaultFunc((xmlGenericErrorFunc)&MyXMLErrorFunction)
> I
> still get: 'main.c:109: passing arg 1 of
> `initGenericErrorDefaultFunc'
> from incompatible pointer type' error.
> 	Argh!
>
>
> Regards,
> 		Jose.
>
> --
>   Death, taxes and Microsoft. If you put it that way, the first two
> don't seem so bad.
>
> On 2 Jun 2004, at 3:37 am, William M. Brack wrote:
>
>> Jose Commins said:
>>>
>>> 	Odd, I am trying to use:
>>>
>>> 	initGenericErrorDefaultFunc((xmlGenericErrorFunc)MyXMLErrorFunction);
>>>
>>> 	But I get this error on compilation:
>>>
>>> 	main.c:109: passing arg 1 of `initGenericErrorDefaultFunc' from
>>> incompatible pointer type
>>>
>>> 	And here's my function:
>>>
>>> void MyXMLErrorFunction(void *ctx, const char *msg, ...)
>>> {
>>> 	printf("Aiee!  And error has occured!\n");
>>> }
>>>
>>>
>>> 	I've tried everything: using the direct address, different
>>> assignments
>>> and so on, but I either get the same error or bus errors.  I *do*
>>> have
>>> this working:
>>>
>>> 	xmlSetGenericErrorFunc(NULL,
>>> (xmlGenericErrorFunc)MyXMLErrorFunction);
>>>
>>> 	And that works fine.
>>>
>>> 	But, am I doing something wrong with the declaration/assignment
>>> of
>>> 'initGenericErrorDefaultFunc' or is it b0rked?
>>>
>>>
>>> Regards,
>>> 		Jose.
>>
>> From xmlerror.h:
>> XMLPUBFUN void XMLCALL
>>     xmlSetGenericErrorFunc      (void *ctx,
>>                                  xmlGenericErrorFunc handler);
>> XMLPUBFUN void XMLCALL
>>     initGenericErrorDefaultFunc (xmlGenericErrorFunc *handler);
>>
>> so perhaps you could try
>>
>> initGenericErrorDefaultFunc(&(xmlGenericErrorFunc)MyXMLErrorFunction);
>>
>> (i.e. use the '&' address-of operator)?
>>
>> Regards,
>>
>> Bill
>>
>>
>
> _______________________________________________
> xml mailing list, project page  http://xmlsoft.org/
> xml gnome org
> http://mail.gnome.org/mailman/listinfo/xml
>





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]