Re: byte data type



Roedy Green wrote:
On Sun, 14 Aug 2005 20:29:05 +0100, Thomas Hawtin
<usenet@xxxxxxxxxxxxxxxxx> wrote or quoted :


C does not specify the number of bits to a char. Nor if it is signed or unsigned (usually they are unsigned). It doesn't even specify if signed chars use two-complement notation.


Yes they had chaos. When people used only 7-bit ASCII it did not
matter, and the signed was a nice feature to use for short offsets.

Back then you had compiler options to consider byte as signed or
unsigned, but tradition left it signed.

I'm pretty sure most compilers went with unsigned (although I may of course be mistaken). unsigned chars mean you can sensible have EOF as -1.


Java went with the signed tradition even though nowadays 99% of the
time you want unsigned.  Perhaps sun hardware is signed byte only.

99% of the time you just don't care. It's important if you are doing byte twiddling to read some format. But then you do it for a few of your simple datatypes and you're done. The only large use is for constants used in the formats.


Java has bytes because it has byte arrays. Same with shorts. IMO, it'd be confusing for some numerical types to be signed and others unsigned. chars as a numerical type was a mistake.

I know Intel circa 386 used be unusually slow at handling signed
bytes.

Surprises me. IIRC, ARMs before the ARM7T (1994) did not have signed byte loads. As you are on the whole unlikely to do anything that makes distinguishes between signed and unsigned on 8-bit data, the 1.5 instruction overhead is not a big deal.


Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
.