![]() |
signed and unsigned char
Hello all,
Is there any particular advantage or reason for always declaring a char to be signed or unsigned? Further, when compiling with gcc on Linux, I received warnings when trying to sprintf an unsigned char *. I presume this is because in Linux the default char type is signed. Is there any way to avoid the error? Or should I not be using unsigned chars where the result would be used with printf, sprintf, etc.? Many thanks, -- Joe |
Re: signed and unsigned char
On 2005-12-14, Joseph Wakeling <joseph.wakeling@gmail.com> wrote:
> Hello all, > > Is there any particular advantage or reason for always declaring a char > to be signed or unsigned? > > Further, when compiling with gcc on Linux, I received warnings when > trying to sprintf an unsigned char *. I presume this is because in > Linux the default char type is signed. Is there any way to avoid the > error? Or should I not be using unsigned chars where the result would > be used with printf, sprintf, etc.? In general, strings should just be char * - if you have an individual char variable, pick signed or unsigned based on what you want it to be. If you have a pointer that points at a block of bytes [some raw data for something], it should be unsigned char * |
Re: signed and unsigned char
Thanks very much! :-)
|
Re: signed and unsigned char
> > Or should I not be using unsigned chars where the result would
> > be used with printf, sprintf, etc.? > > In general, strings should just be char * - if you have an individual > char variable, pick signed or unsigned based on what you want it to be. > If you have a pointer that points at a block of bytes [some raw data for > something], it should be unsigned char * What about strings using some extended character encoding, iso-8859-1 for example; are those to be considered as binary data (unsigned char *) or regular strings (char *) ? Is printf()'ing these strings legal ? |
Re: signed and unsigned char
On 2005-12-14, Gerr <gertvierman@hotmail.com> wrote:
>> > Or should I not be using unsigned chars where the result would >> > be used with printf, sprintf, etc.? >> >> In general, strings should just be char * - if you have an individual >> char variable, pick signed or unsigned based on what you want it to be. >> If you have a pointer that points at a block of bytes [some raw data for >> something], it should be unsigned char * > > What about strings using some extended character encoding, iso-8859-1 > for example; are those to be considered as binary data (unsigned char > *) or regular > strings (char *) ? Is printf()'ing these strings legal ? read your implementation docs. but consider that "strings" i.e. string literals have type char *. |
| All times are GMT. The time now is 06:13 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.