views:

456

answers:

1

On the MSVC++ compiler, one can use the __int8, __int16, __int32 and similar types for integers with specific sizes. This is extremely useful for applications which need to work with low-level data structures like custom file formats, hardware control data structures and the like.

Is there a similar equivalent I can use on the GCC compiler?

+19  A: 

In POSIX, stdint.h defines these. You can use:

uint8_t  - unsigned 8 bit
int8_t   - signed 8 bit
uint16_t - unsigned 16 bit
int16_t  - signed 16 bit
uint32_t - unsigned 32 bit

etc... I used these types all the time.

Jason Coco
stdint.h is also part of C99, so it's no longer posix-specific.
puetzk
I see. I vaguely remember seeing a compiler attribute that does something similar....
Pramod
Oh, that's good to know, thanks puetzk :)
Jason Coco
I remember having this problem the other way around many years ago (not uint8_t on Microsoft) :)
Robert Gould
@Pramod: it exists, but you do not want to use it. It is __attribute__((mode(...)))
CesarB
@Robert Gould: Check out http://code.google.com/p/msinttypes/
bobobobo