On Apr 1, 8:30 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2008-04-01 14:58, James Kanze wrote:
On Apr 1, 8:24 am, Kai-Uwe Bux <jkherci...@gmx.netwrote:
lazy wrote:
Is there a datatype for byte?
I want to write an API that takes in an array of bytes.
I can use char array, but not sure if sizeof(char) will always be 1
now or in future on all machines(32/64bit) and compilers.
Is sizeof(char) always gauranteed to be one?
sizeof(char) is guaranteed to be one.
However, a char is not guaranteed to be an octet of bits.
Neither is a byte. I've seen bytes of 6, 7 and 9 bits as well,
and on a PDP-10, the size of a byte was programmable.
I think, however, that the minimal size of a char in C++ is 7
bits since the standard identifies at least 99 characters in
the basic character set which must be encodable in a char
(sections 2.2 and 3.9.1 in the standard).
The C and C++ standards use a non-standard definition of byte.
They require a byte to have at least 8 bits (since the smallest
legal value of UCHAR_MAX is 255); they also speak of bytes
regardless of the implementation, where as of course, many early
machines didn't have bytes at all. (Thus, for example, when a
DSP defines CHAR_BIT as 32, and sizeof( int ) == sizeof( char ),
the C/C++ standard speaks of 32 bit bytes, when according to the
traditional definition, there are no bytes, just words.)
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34