What is uint_fast32_t and why should it be used instead of regular int and uint32_t?

Thus, the reason for typedef : ed of primitive data types is to abstract the low-level representation and make it easier to understand ( uint64_t instead of the long long type, which is 8 bytes).

However, there is uint_fast32_t that has the same typedef as uint32_t . Will using the โ€œfastโ€ version speed up program execution?

+72
c ++ c types
Dec 14 '11 at 7:11
source share
4 answers
  • int can be like 16 bits on some platforms. This may not be enough for your application.
  • uint32_t not guaranteed. This is an optional typedef that the implementation should provide if it has an unsigned integer type of exactly 32 bits. For example, some have 9-bit bytes, so they do not have uint32_t .
  • uint_fast32_t clearly states its intention: it is a type of at least 32 bits that is best suited for performance. uint_fast32_t may actually be 64 bits long. This is before implementation.

... there is uint_fast32_t that has the same typedef as uint32_t ...

What you are watching is not standard. This is a special implementation (BlackBerry). Therefore, you cannot conclude that uint_fast32_t always matches uint32_t .

See also:

+90
Dec 14 '11 at 7:20
source share

The difference lies in their accuracy and availability.

doc here says:

unsigned integer type with exactly 8, 16, 32 and 64 bit widths respectively ( provided only if the implementation directly supports the type ):

 uint8_t uint16_t uint32_t uint64_t 

and

the fastest unsigned unsigned integer type with a width of at least 8, 16, 32 and 64 bits, respectively

 uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t 

So the difference is pretty much obvious: uint32_t is a type that has exactly 32 bits, and an implementation should only provide it if it has a type with exactly 32 bits, and then it can introduce typedef as uint32_t . This means that uint32_t may or may not be available.

uint_fast32_t , uint_fast32_t other hand, is a type that has at least 32 bits, which also means that an implementation can typedef uint32_t as uint_fast32_t if it provides uint32_t . If it does not provide uint32_t , then uint_fast32_t can be a typedef of any type that has at least 32 bits.

+25
Dec 14 '11 at 7:26
source share

When you #include inttypes.h in your program, you get access to many different ways of representing integers.

The uint_fast * _t type simply defines the fastest type to represent a given number of bits.

Think of it this way: you define a variable of type short and use it several times in the program, which is completely valid. However, the system you are working on can work faster with int values. By defining a variable as uint_fast*t , the computer simply selects the most efficient representation with which it can work.

If there is no difference between these representations, the system selects what it wants and uses it sequentially.

+2
Dec 14 '11 at 7:24 a.m.
source share

Please note that the fast version may be more than 32 bits. While the fast int will fit well into the register and be aligned and the like: but it will use more memory. If you have large arrays, your program will be slower due to more memory access and throughput.

I donโ€™t think that modern CPUS will benefit from fast_int32, since in the general case the sign extension from 32 to 64 bits can occur during the boot command, but the idea that there is a โ€œnativeโ€ integer format that is faster, old-fashioned.

0
Oct 27 '17 at 16:54 on
source share



All Articles