What is the difference between intXX_t and int_fastXX_t?

前端 未结 4 1728
挽巷
挽巷 2021-01-31 01:51

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 archit

4条回答
  •  自闭症患者
    2021-01-31 02:25

    IMO they are pretty pointless.

    The compiler doesn't care what you call a type, only what size it is and what rules apply to it. so if int, in32_t and int_fast32_t are all 32-bits on your platform they will almost certainly all perform the same.

    The theory is that implementers of the language should chose based on what is fastest on their hardware but the standard writers never pinned down a clear definition of fastest. Add that to the fact that platform maintainers are reluctant to change the definition of such types (because it would be an ABI break) and the definitions end up arbitrarily picked at the start of a platforms life (or inherited from other platforms the C library was ported from) and never touched again.

    If you are at the level of micro-optimisation that you think variable size may make a significant difference then benchmark the different options with your code on your processor. Otherwise don't worry about it. The "fast" types don't add anything useful IMO.

提交回复
热议问题