Re: How to convert gchar to char in C language?



"Mee Com" wrote:

In gtk+2.0 the variable for character is "gchar",
so if my code include file which write in C Language ,
that use the type of character is "char" or "unsigned char"
such as char a;
how do I change the format of gchar to char? or how do I change format
of char to gchar?
that I can recieve input from the file which I included.
For example, I want to include the file write_in_C_language.c which
has char a;
how do I recieve the value from char a to my application which write
with GTK. that in my GTK file use gcha,such as gchar x;?
                 when I use gchar x = a;
                when compiled,it said incorrect formatted data
                type,that I knew it,but how do I solve this problem?

See glib/types.h:

typedef char   gchar;

In other words: "gchar" is just a Glib-specific alias for "char". There
is no need for a real conversion since their data format is identical.

What you should get when assigning a "char" with a "gchar" value (or
vice versa) is a compiler warning only. (Some compilers may be fussier
about it, however.) That's just because the names of the types of the
variables differ, while their contents don't. The resulting code would
work fine (though the warnings are ugly).

Use type casts to avoid warnings when assigning across different
variable types. I.e.:

char a;
gchar x;
x = (gchar) a;



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