Data type problem

Ralf Corsepius ralf.corsepius at rtems.org
Mon Oct 15 10:23:09 CDT 2007


On Mon, 2007-10-15 at 15:15 +0200, Juergen Zeller wrote:
> try things like this:
> 
> typedef signed char        int8;
> typedef unsigned char      uint8;
> typedef signed short       int16;
> typedef unsigned short     uint16;
> typedef signed int         int32;
> typedef unsigned int       uint32;
> typedef signed long long   int64;
> typedef unsigned long long uint64;

Don't!

These are (POSIX, ANSII, ISO, C99) standardized types you are not
supposed to define/typedef.

As Joel already wrote: #include <stdint.h>

> typedef unsigned char      byte;
> typedef unsigned short int word;
> typedef unsigned int       dword;

If you really need fixed size types, use uint8_t, uint16_t etc.

If you need a "byte" (in the sense of "minimal addressable machine
unit") use "signed char" or "unsigned char".

If you need 8-bit types, use uint8_t rsp. int8_t. 



Though on most modern architectures the assumptions of "char == byte ==
8bit" etc. apply, there is no guarantee that they really are.
Esp. on embedded targets these occasionally do NOT apply.

E.g. in RTEMS, we have several architectures for which "int == 16bit"
applies, and we have one architecture for which 
"char == short == int == 32bit" applies.

Ralf






More information about the rtems-users mailing list