Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > signed and unsigned char

Reply
Thread Tools

signed and unsigned char

 
 
Joseph Wakeling
Guest
Posts: n/a
 
      12-14-2005
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

 
Reply With Quote
 
 
 
 
Jordan Abel
Guest
Posts: n/a
 
      12-14-2005
On 2005-12-14, Joseph Wakeling <(E-Mail Removed)> 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 *
 
Reply With Quote
 
 
 
 
Joseph Wakeling
Guest
Posts: n/a
 
      12-14-2005
Thanks very much!

 
Reply With Quote
 
Gerr
Guest
Posts: n/a
 
      12-14-2005
> > 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 ?

 
Reply With Quote
 
Jordan Abel
Guest
Posts: n/a
 
      12-14-2005
On 2005-12-14, Gerr <(E-Mail Removed)> 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 *.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Padding bits and char, unsigned char, signed char Ioannis Vranos C Programming 6 03-29-2008 10:55 AM
Padding bits and char, unsigned char, signed char Ioannis Vranos C++ 11 03-28-2008 10:47 PM
char vs. signed or unsigned char At_sea_with_C C Programming 4 03-14-2007 08:28 PM
void*, char*, unsigned char*, signed char* Steffen Fiksdal C Programming 1 05-09-2005 02:33 AM
signed char and unsigned char difference dam_fool_2003@yahoo.com C Programming 9 07-26-2004 01:59 AM



Advertisments