Search code examples
ctypedefavr-gcc

Purpose of typedef int16_t int_fast16_t in avr-gcc library


I am now going through avr library in "Arduino\hardware\tools\avr\avr\include" folder. In stdint.h file there is the piece of code:

typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
typedef signed int int32_t __attribute__ ((__mode__ (__SI__)));

typedef uint16_t uint_fast16_t;

/** \ingroup avr_stdint
    fastest signed int with at least 32 bits. */

typedef int32_t int_fast32_t;

So basically int32_t, int_fast32_t and signed int __attribute__ ((__mode__ (__SI__))) are the same thing. Could anybody confirm that?

If yes, why is it done in such way? Why don't just use int32_t?


Solution

  • I understand the question to be "Why does stdint.h declare types with names like int_leastN_t and int_fastN_t as well as the intN_t that I expect it to declare?"

    The simple answer is that the C standard (since its 1999 revision) requires stdint.h to declare those types, because the committee thought they would be useful. As it happens, they were wrong; almost nobody wants anything out of stdint.h but the exact-width types. But it is very, very rare for anything to get removed from the C standard once it's been included, because that would break programs that are using them. So stdint.h will probably continue to declare these types forever.

    (I could go on at considerable length about why non-exact-width types are less than useful in C, but you probably don't care.)