473,320 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

char vs. signed or unsigned char

hello all,

Is there a reason to prefer char over signed or unsigned char. From waht I
know all strings can be coded with unsigned char while a negative number
can be put in signed char. So what are the uses for plain char?

Thanks to all who ansered my last post (enum).

--
Email: The handle, (dot seperated), at gmail dot com.
Mar 14 '07 #1
4 31723
At_sea_with_C <bl********@dev.null.invalidwrote:
Is there a reason to prefer char over signed or unsigned char. From waht I
know all strings can be coded with unsigned char while a negative number
can be put in signed char. So what are the uses for plain char?
As far as I know, there is no "plain char". A char is either a unsigned
char or a signed char, which exactly is implementation depenedent:

ISO/IEC 9899:1999, 6.2.5.15 (p. 49)
The three types char, signed char, and unsigned char are collectively called
the character types. The implementation shall define char to have the same range,
representation, and behavior as either signed char or unsigned char.
HTH,
Flo
Mar 14 '07 #2
Florian Weingarten wrote:
At_sea_with_C <bl********@dev.null.invalidwrote:
>Is there a reason to prefer char over signed or unsigned char. From waht I
know all strings can be coded with unsigned char while a negative number
can be put in signed char. So what are the uses for plain char?

As far as I know, there is no "plain char".
`char` is plain.
A char is either a unsigned char or a signed char, which exactly
is implementation depenedent:

ISO/IEC 9899:1999, 6.2.5.15 (p. 49)
The three types char, signed char, and unsigned char are collectively called
the character types. The implementation shall define char to have the same range,
representation, and behavior as either signed char or unsigned char.
No: it has the same range, representation, and behaviour as one of
those types, but it's a different type.

I'd expect the implementation to pick whichever one was "more
efficient" by some reasonable measure - eg when converting to
`int`, one probably wants an efficient code sequence, so one
picks whatever the machine conversion is (PDP11 MOVB, for example)
and takes the consequences.

--
Chris "electric hedgehog" Dollin
"We live for the One, you die for the One." Unsaid /Babylon 5/.

Mar 14 '07 #3
At_sea_with_C wrote:
Is there a reason to prefer char over signed or unsigned char. From waht I
know all strings can be coded with unsigned char while a negative number
can be put in signed char. So what are the uses for plain char?
use char for character data (supported by the implementation)

use unsigned char for raw data, eg. data transmitted over a comms link

I've never used signed char, I suppose you'd use it for small signed
integers
--
Nick Keighley

Mar 14 '07 #4
"Nick Keighley" <ni******************@hotmail.comwrote in message
>
I've never used signed char, I suppose you'd use it for small signed
integers
One use is for normals in runtime graphics.
Three numbers in the range -128 to 127 give you enough resolution to do
visually acceptable lighting, but don't take up too much space, and you can
use fast integer arithmetic.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


Mar 14 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: hs | last post by:
Is the following correct? void foo(int len, char* val) { .. .. .. unsigned char* string = (unsigned char*) new char ; memcpy(string, val, len); ..
9
by: dam_fool_2003 | last post by:
For int data type the default range starts from signed to unsigned. If we don't want negative value we can force an unsigned value. The same goes for long also. But I don't understand why we have...
9
by: Magix | last post by:
Hi, char is 8 bit from -127 to 127 unsigned char is 8 bit from 0-255 from ASCII table, there is a list of char from 0-255. How char can be in negative value ? If I declare "char x", then can...
11
by: jamx | last post by:
I need to compare the following values: char buf; /* buf is filled using COMport here... */ if (buf == 0x85) { /* do something */ }
6
by: Steven Jones | last post by:
Can anybody illustrate the usefulness of having char and unsigned char? I mean, under what circumstances would one want to use unsigned char (or unsigned char *) rather than char (or char *,...
1
by: kunal patil | last post by:
Is there any significant difference (apart from range) in signed char and unsigned char in 'C'. wt can be an application of signed char??
4
by: HackerisNewKnight | last post by:
Hello, 1) First problem. In my project i need to convert from char* to BYTE*( BYTE is unsigned char), is there any way to make the convertion? BYTE* bite; char* ch="help me, please"; bite =...
1
by: bindiya182003 | last post by:
Difference between the datatypes char and unsigned char? When we hav to use them??Please give examples also
1
by: freeurmind | last post by:
i'm having a lot of problem converting a char pointer to unsigned char *, i tried all types of casting and nothing worked, what i'm doing is: char * message = "Mymessage"; unsigned char * umessage...
8
by: KYAW KYAW OO | last post by:
Dear All, Now, I am stuck above question so long and I would like to get Red, Green and Blue as unsigned char * each from unsigned char * of 24 bit BMP Color images. e.g unsigned char *...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.