On 07/02/2012 10:33 PM, Mouse wrote:
> AFAIK
sizeof(unsigned short) is not defined anywhere :-).
(looks around office, sees six different
architectures where it's
sixteen bits)
Huh? It's pretty well-defined here.
Once upon a time, all the world was a VAX running 4.x. Then Sun
happened, and lots of code that "worked everywhere" broke.
Later, all the world was a 386/486/Pentium, SPARC, PowerPC, etc. Then
amd64 and sparc64 happened and lots of code that "worked everywhere"
broke.
Write to what the language promises, not what happens to be popular
today. Those who have to maintain your code in the future will thank
you.
Or don't. Those who fix it in the future will thank you for their job
security.
Or, of course, you could just not even pretend to write portably.
Sometimes that's a right answer; for example, when writing a driver for
an SBus device, I have no problem assuming I'm on a SPARC.
I'm writing device drivers and comm protocols for industrial control
systems. These boards will be made by the hundreds of thousands and
will never run any other processor. End of story.
Yes, I've laughed at such short-sightedness before, but in this case,
it is 100% true.
Further, code I wrote 25 years ago in C, using "unsigned int" and
"unsigned short" all over the place, works just friggin' fine. And that
stuff is NOT embedded industrial control code...it's APPLICATION code.
It now runs beautifully on 64-bit systems, and I haven't touched it in
two decades.
Do not make the mistake of assuming that I don't know this language,
and don't make the mistake of assuming that anyone who doesn't use this
"uint32_t" noise is automatically writing inherently non-portable code.
I know *you* know C well enough to know better. Be aware that I do as
well, because we've probably been doing it just about as long.
-Dave
--
Dave McGuire, AK4HZ
New Kensington, PA