I have recently discovered existence of standard fastest type, mainly int_fast32_t and int_fast64_t.
I was always told that, for normal use on mainstream architecture, one should better use classical int & long which should always fit to the processor default reading capacity and so avoid useless numeric conversions.
In the C99 Standard, it says in §7.18.1.3p2 :
"The typedef name int_fastN_t designates the fastest signed integer type with a width of at least N. The typedef name uint_fastN_t designates the fastest unsigned integer type with a width of at least N."
And there is also a quote about it in §7.18.1.3p1 :
"The designated type is not guaranteed to be fastest for all purposes; if the implementation has no clear grounds for choosing one type over another, it will simply pick some integer type satisfying the signedness and width requirements."
It's unclear to me what fastest really means. I do not understand when I should use this type and when I should not.
I have googled a little on this and found that some open source projects have changed some of their functions to it, but not all of them. They didn't really explain why they have changed a part, and only a part, of their code to it.
Do you know what are the specific cases/usages when int_fastXX_t are really faster than the classical ones ?
Best Answer
In the C99 Standard, 7.18.1.3 Fastest minimum-width integer types.
and
The types
int_fastN_t
anduint_fastN_t
are counterparts to the exact-width integer typesintN_t
anduintN_t
. The implementation guarantees that they take at leastN
bits, but the implementation can take more bits if it can perform optimization using larger types; it just guarantees they take at leastN
bits.For example, on a 32-bit machine,
uint_fast16_t
could be defined as anunsigned int
rather than as anunsigned short
because working with types of machine word size would be more efficent.Another reason of their existence is the exact-width integer types are optional in C but the fastest minimum-width integer types and the minimum-width integer types (
int_leastN_t
anduint_leastN_t
) are required.