AFAIK
sizeof(unsigned short) is not defined anywhere :-).
I'm not sure I follow you here. In C, you can indeed do a
sizeof(unsigned short)
and get back the size (in characters) of a short int (with the size in
bits of a character defined by CHAR_BIT).
But it's not defined in a standard, which is a problem. It could be 128
bits when it's compiled for all you know.
Um .. it *IS* defined in a standard---the ANSI C standard:
... Their implementation defined values shall be equal or greater in
magnitude (absolute value) to those shown, with the same sign.
CHAR_BIT - number of bits for smallest object that is not a
bit-field (byte)
CHAR_BIT 8
(C Standard, section 5.2.4.2.1)
Here's a fun one. Up unti Firefox 10, Mozilla used a manufactured internal
type called PRBool which essentially was unsigned char. At that point, they
decided to switch all usage of PRBool to "native" C++ bool.
Guess what happened on those systems where Boolean didn't map to an 8-bit
quantity?
Guess what big-endian architecture I am a large proponent of was one of
those architectures? (For bonus points, what is sizeof(bool) on this
architecture?)
Fortunately they only made this assumption a few places, but figuring out
what broke was maddeningly fiddly. Most places were memset()s that failed
to fully initialize a block of memory, leading to unpredictable behaviour.
--
------------------------------------ personal:
http://www.cameronkaiser.com/ --
Cameron Kaiser * Floodgap Systems *
www.floodgap.com * ckaiser at
floodgap.com
-- I do not fear computers. I fear the lack of them. -- Isaac Asimov ----------