What is the difference between the int types int8_t
, int_least8_t
and int_fast8_t
?

- 7,813
- 9
- 47
- 65
-
Why did you accept a wrong answer when there are quite good answers here? – Jim Balter Mar 10 '11 at 01:51
-
7In fact, every single answer here **except** the one you accepted is both correct and informative. – Jim Balter Mar 10 '11 at 01:57
-
@Jim, my answer was incorrect but not so incorrect that everyone seems to think. The only thing I was wrong on was int_least8_t. Regardless, I've edited it to be correct – Earlz Mar 10 '11 at 03:03
-
@Earlz In other words, it was right about int8_t and wrong about everything else. As for what "everyone seems to think", neither you nor I know that, but there can't be that many because your answer didn't get nearly the number of downvotes it should have. – Jim Balter Mar 10 '11 at 04:14
5 Answers
The difference is defined in the sections of the C99 standard that Carl Norum quoted. But it may be useful to have an example.
Suppose you have a C compiler for a 36-bit system, with char
= 9 bits, short
= 18 bits, int
= 36 bits, and long
= 72 bits. Then
int8_t
does not exist, because there is no way to satisfy the constraint of having exactly 8 value bits with no padding.int_least8_t
is a typedef ofchar
. NOT ofshort
orint
, because the standard requires the smallest type with at least 8 bits.int_fast8_t
can be anything. It's likely to be a typedef ofint
if the "native" size is considered to be "fast".

- 87,747
- 23
- 163
- 198
From the spec section 7.8.1.1 Exact-width integer types, paragraph 1:
The typedef name
int
N_t
designates a signed integer type with width N , no padding bits, and a two’s complement representation. Thus,int8_t
denotes a signed integer type with a width of exactly 8 bits.
And from: 7.18.1.2 Minimum-width integer types, paragraph 1:
The typedef name
int_least
N_t
designates a signed integer type with a width of at least N, such that no signed integer type with lesser size has at least the specified width. Thus,int_least32_t
denotes a signed integer type with a width of at least 32 bits.
And finally from 7.18.1.3 Fastest minimum-width integer types, paragraph 2:
The typedef name
int_fast
N_t
designates the fastest signed integer type with a width of at least N. The typedef nameuint_fast
N_t
designates the fastest unsigned integer type with a width of at least N.

- 219,201
- 40
- 422
- 469
Here's a conceptually simple answer: the width of int*N_t for all three types must be >= N. intN_t has exactly N bits, int_leastN_t is the least (narrowest) such type, and int_fastN_t is the fastest such type.
For example, on a machine with 8 bit bytes and 32 bit fast registers, int8_t and int_least8_t are aliased to signed char but int_fast8_t is aliased to int32_t. Whereas, if the implementation chose to define them, int_least24_t and int_fast24_t would both be aliased to int32_t, with int24_t left undefined.
Edit: as Technophile points out below, the real issue for fast types is memory, not registers (generally, operations on the low-order bits of registers can be done just as fast as on the whole register). For example, writing to an int8_t in memory may require loading the 32-bit word containing it, modifying just the byte, and then writing it back, whereas if it were stored in a 32-word it could be written without reading.

- 16,163
- 3
- 43
- 66
-
3Only after reading *this* answer did I became aware of the importance of *int_fastN_t* types. *N bit registers*. It is painfully obvious, however coming from an object-oriented world (Java) it is hard to realize this at first (on one's own at least). – Kohányi Róbert Nov 12 '11 at 07:22
-
3@Kohányi Róbert: it is not because of Java being object-oriented (also is C++). it is because Java is machine-independent (abstract). this is why the notion of "register" is rather meaningless (and also forbidden) in Java. – user1284631 Oct 21 '12 at 19:13
-
@axeoth You're right that it has nothing to do with being object-oriented, but the whole point of these types, esp. the least and fast versions, is machine independence. Java is actually more machine-dependent because its int types are CONCRETE -- they have predefined and fixed sizes ... it's impossible to implement Java on a machine without 8-bit bytes. And the issue of registers isn't relevant ... registers are not part of the C memory model and the "register" keyword is ignored by most compilers, but C and Java compilers of course both generate register code. – Jim Balter Oct 21 '12 at 19:33
-
3@Kohányi Róbert: this could be related to memory accesses. For example suppose that memory is 64-bit words. Consider how an 8-, 16- or 32-bit value would be written to a memory location: the processor might have to read memory, modify the desired bits then write a 64-bit value, while a 64-bit value could be written in a single access. – Technophile Jul 28 '14 at 21:34
-
1This is the only answer that even attempted to answer the question I came here to get answered, so I am surprised it hasn't been upvoted more. I suspected that this was what 'fast' was for, but I wanted to make sure, so thank you all for confirming that it is related to CPU operation and RAM access details. – RTHarston Jan 20 '20 at 19:56
intN_t
(and uintN_t
) is not required in all C99 implementations. These types are the "exact-width integer types". They are required in implementations where it makes sense to have them (basically every desktop computer).
int_leastN_t
is required in all C99 implementation for values of N of 8, 16, 32, and 64. This is the "minimum-width integer types".
int_fastN_t
is required in all C99 implementation for values of N of 8, 16, 32, and 64. This is the "fastest minimum-width integer types".

- 106,608
- 13
- 126
- 198
-
1This is better because it adds what is required to be conformant and what is optional. +1 from me. – Anurag Kalia Apr 30 '13 at 16:41
These are related to the size of the integer and are just what they sound like.
int8_t is exactly 8 bits
int_least8_t is the smallest int type that has at least 8 bits
int_fast8_t is the fastest int type that has at least 8 bits.

- 16,163
- 3
- 43
- 66

- 69,564
- 10
- 76
- 117
-
4This doesn't really serve to explain the difference, which was the point of the original question. – Conrad Meyer Mar 10 '11 at 01:48
-
@Jim Balter: What's the difference between `int_least8_t` and `int_fast8_t` according to this answer, then, huh? – Conrad Meyer Mar 10 '11 at 04:57
-
2@Conrad The answer is merely missing the words "is the smallest type that" from the second line. Huh. – Jim Balter Mar 10 '11 at 05:44
-
@Conrad Yes, that's right. What, you expected that int_least8_t might be long long? int8_t is explained to be exact, int_fast8_t is explained to be fastest; that explains 2/3 of the difference. The explanation for int_least8_t is flawed but easy to figure out if one expends the **least** amount of effort. – Jim Balter Mar 10 '11 at 06:38
-
@Conrad And BTW, the accepted answer, about which the OP wrote "This really explains why they exist in the first place", was grossly wrong when accepted, and **still**, even after the edit, has the very same flaw that you claim causes this to not "serve to explain the difference". The critical comments on that answer bother to point out what's wrong with it. – Jim Balter Mar 10 '11 at 06:55
-
The comment above refers to the originally accepted answer from Earlz which has since been deleted. – Jim Balter Sep 30 '17 at 03:07