On Mon, 02 Jul 2012 19:26:37 -0400
Dave McGuire <mcguire at neurotica.com> wrote:
On every platform I work on, and indeed every platform
I've
*ever* worked on, unsigned short has been 16 bits, and unsigned int has
been 32. That includes the 8-bitters as well.
No. avr-gcc uses 16 bits / 2 bytes
for int / unsigned int.
I am looking at this very moment to a LCD connected to a ATmega168 that
printed sizeof( unsigned int) on said LCD.
Your confusion about sizeof( int) is the exact reason why uint32_t and
its friends where introduced with C99.
IIRC a int is 16 bits on 2.11BSD too, as the PDP-11 is a 16 bit
machine. But it is way to long ago since I hacked C on my 2.11BSD
machine. So I may be wrong on this.
The point is: An int is usuly the largest intish type a machine can
handle "comfortly". This is true for the AVR, as at least some AVRs
have instructions that work on 16 bit values. Also: sizeof( int) is
expected to be > sizeof( char). (> not >=) So if we imply char to be a
8 bit byte an int must be at least 16 bits. Thus sizeof( int) == 2 for
the AVR, since sizeof( int) == 4 would be to much overhead.
The 16 bitnes of the PDP-11 is well knowen.
Regarding uint32_t and its friends: They are in the C99 standard.
(inttypes.h) I use them all over the place. Especially on AVRs. I wrote
C code that I compiled without change on an AVR and on a PeeCee running
NetBSD/i386. I used (u)int(16|32)_t all over there to avoid the
sizeof( int) missmatch. This was important, as I did some fixed piont
arthmetic.
--
\end{Jochen}
\ref{http://www.unixag-kl.fh-kl.de/~jkunz/}