signed and unsigned char

J

Joseph Wakeling

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
 
J

Jordan Abel

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 *
 
G

Gerr

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 ?
 
J

Jordan Abel

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 *.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top