[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: [xml] xmlChar double ptr
- From: "Aron Stansvik" <elvstone gmail com>
- To: libxml2 <xml gnome org>
- Subject: Re: [xml] xmlChar double ptr
- Date: Tue, 6 May 2008 16:59:41 +0200
2008/5/6 <david hagood gmail com>:
> > Hei,
> > how do i define a double ptr xmlChar? is it possible at all?
> > static xmlChar* mapper[] = {"bla", "blubber"} ;
> >
> > doesn't work. g++ says
> > XMLStructure.h:75: error: invalid conversion from 'const char*' to
> > 'xmlChar*'
> >
>
> There's 2 problems here:
> One is that, under many configurations of g++, quoted strings are of type
> "const char []", which will coerce to "const char *". Since you are
> assigning them to a non-const pointer, this is a const-ness violation.
> Changing your variable to "const xmlChar *" (or better still "const
> xmlChar * const") would help this.
>
> (BTW: in C++ "const" implies "static". Also, making the array of pointers
> itself constant is good practice, hence my recommendation of "const
> xmlChar * const")
Duh. I accidently typed g++ instead of gcc when testing. That's why I
got no error.
>
> The second is that "xmlChar" is actually "unsigned char", so you are again
> crossing a type, and that will ALSO be an error.
>
> The best way around this would be to cast the strings, thus:
> const xmlChar *const mapper[] =
> {
> reinterpret_cast<const xmlChar *>("bla"),
> reinterpret_cast<const xmlChar *>("blubber")
> };
>
> You could also use the libxml2 "BAD_CAST" macro:
> const xmlChar *const mapper[] =
> {
> BAD_CAST "bla",
> BAD_CAST "blubber"
>
>
> };
>
>
> _______________________________________________
> 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]