View Single Post
  #2 (permalink)  
Old 07-22-2007, 08:24 PM
rpgfan3233 rpgfan3233 is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jul 2007
Posts: 118
iTrader: (0)
rpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura about
There isn't really any difference when it comes to C and C++. The languages state that the default of any integer type (char, short (int), int, long (int) and long long (int) in C99) is signed. With normal integers, determining whether to use signed vs unsigned is as simple as asking yourself the following question: do you wish to allow for negative values? If you want to allow yourself to use negative values (or your users if you are creating an API or your fellow coders if you are creating an open source application for others to freely modify), choose signed. Note that with the char data type, signed vs unsigned doesn't matter. 0 to 127 is the same. -128 to -1 (signed) is the same as 128 to 255 (unsigned), even in binary.

That's probably why there is an option in some versions of Visual Studio to allow for changing the default to unsigned char. After all, working with negative values seems somewhat unnatural.

__________________
"C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off."
-- Bjarne Stroustrup, creator of what is now known as C++
For more quotes by Bjarne Stroustrup, check out http://www.research.att.com/~bs/bs_faq.html#really-say-that.
Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
The Following 3 Users Say Thank You to rpgfan3233 For This Useful Post:
HelloWorld (07-23-2007), Lee (07-23-2007), TeraTask (07-22-2007)