Why would uint32_t be preferred rather than uint_fast32_t?

前端 未结 11 1180
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 00:58

It seems that uint32_t is much more prevalent than uint_fast32_t (I realise this is anecdotal evidence). That seems counter-intuitive to me, though.

11条回答
  •  广开言路
    2021-01-31 01:38

    Several reasons.

    1. Many people don't know the 'fast' types exist.
    2. It's more verbose to type.
    3. It's harder to reason about your programs behaviour when you don't know the actual size of the type.
    4. The standard doesn't actually pin down fastest, nor can it really what type is actually fastest can be very context dependent.
    5. I have seen no evidence of platform developers putting any thought into the size of these types when defining their platforms. For example on x86-64 Linux the "fast" types are all 64-bit even though x86-64 has hardware support for fast operations on 32-bit values.

    In summary the "fast" types are worthless garbage. If you really need to figure out what type is fastest for a given application you need to benchmark your code on your compiler.

提交回复
热议问题