proper way to create a GString object from an unsigned char *
- From: Adam Monsen <haircut gmail com>
- To: gtk-app-devel-list gnome org
- Subject: proper way to create a GString object from an unsigned char *
- Date: Fri, 23 Jul 2004 12:36:28 -0700
What's the proper way to create a GString object from an unsigned char*?
I ask because I'm using libxml, and libxml has a xmlChar type (which
is an unsigned char). If I make an xmlChar* = "Hello World", how
should I make this into a GString?
Is it wrong to just cast xmlChar* to char*, even though xmlChar is an
unsigned char?
Here's a small program demonstrating the warning from gcc that I want
to alleviate:
-------------------------------------------8<-------------------------------------------
#include <libxml/xmlstring.h>
#include <glib-2.0/glib.h>
#include <stdio.h>
/*
gcc -Wall -ansi -pedantic `pkg-config --cflags --libs libxml-2.0
glib-2.0` xmlchar.c
*/
int
main (void)
{
xmlChar *xmlstr;
GString *gstr;
/* METHOD 0: gcc warns */
xmlstr = xmlCharStrdup ("Hello World -- gcc warning");
gstr = g_string_new (xmlstr);
printf ("%s\n", gstr->str);
g_string_free (gstr, FALSE);
/* METHOD 1: with cast ... no warning from gcc */
xmlstr = xmlCharStrdup ("Hello World -- with cast, no warning");
gstr = g_string_new ((char *) xmlstr);
printf ("%s\n", gstr->str);
g_string_free (gstr, FALSE);
return 0;
}
------------------------------------------->8-------------------------------------------
--
Adam Monsen <adamm wazamatta com>
http://adammonsen.com/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]