I should clarify. Yes, you can get sizeof(whatever)
and it will be
the size of whatever in bytes;
...well, for "byte" == "the storage for a `char'"...
I meant that sizeof(unsigned short) is undefined by a
standard.
True, but there is a minimum size in bits (16) implied; SHRT_MIN must
be <= -32767, SHRT_MAX must be >= 32767, and USHRT_MAX must be >= 65535.
Assuming that it has even a fixed minimum (1 char
notwithstanding)
Yeah, sizeof(unsigned short) can be as low as 1. While I've never
personally seen one, I've heard of compilers targeted at DSPs which
make char, short, int, and long all the same: one (32-bit) machine
word.
I think actually the most obnoxious example I've
seen is the
assumption that sizeof(int) == sizeof(void *).
Oh, yeah. I've run into that a few times (or more often assuming that
any pointer can be shoved into an int and pulled back without change,
which is pretty close to assuming sizeof(int) >= sizeof(void *)).
Or consider Xt, at least as of MIT X vintage, which I think assumes the
other way around (which is less likely to fail in practice, but just as
not-guaranteed). It's one of the more personally annoying examples
I've seen of playing fast and loose with pointers-vs-integers.
/~\ The ASCII Mouse
\ / Ribbon Campaign
X Against HTML mouse at
rodents-montreal.org
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B