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?
ISO standard C, starting with the C99 standard, adds the standard header
<stdint.h>that defines these:I use these types all the time.
These types are defined only if the implementation supports predefined types with the appropriate sizes and characteristics (which most do).
<stdint.h>also defines types with names of the form(u)int_leastN_t(types that have at least the specified width) and(u)int_fastN_t(the ‘fastest’ types that have at least the specified width); these types are mandatory.If you’re using an old implementation that doesn’t support
<stdint.h>, you can roll your own; one implementation is Doug Gwyn’s ‘q8’.