Difference between different integer types

后端 未结 4 2039
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 15:37

I was wondering what is the difference between uint32_t and uint32, and when I looked in the header files it had this:

types.h:

           


        
相关标签:
4条回答
  • 2020-12-08 15:47

    unsigned and unsigned int are synonymous for historical reasons; they both mean "unsigned integer of the most natural size for the CPU architecture/platform", which is often (but by no means always) 32 bits on modern platforms.

    <stdint.h> is a standard header in C99 that is supposed to give type definitions for integers of particular sizes, with the uint32_t naming convention.

    The <types.h> that you're looking at appears to be non-standard and presumably belongs to some framework your project is using. Its uint32 typedef is compatible with uint32_t. Whether you should use one or the other in your code is a question for your manager.

    0 讨论(0)
  • 2020-12-08 15:50

    unsigned and unsigned int are synonymous, much like unsigned short [int] and unsigned long [int].

    uint32_t is a type that's (optionally) defined by the C standard. uint32 is just a name you made up, although it happens to be defined as the same thing.

    0 讨论(0)
  • 2020-12-08 15:55

    There is absolutely no difference between unsigned and unsigned int.

    Whether that type is a good match for uint32_t is implementation-dependant though; an int could be "shorter" than 32 bits.

    0 讨论(0)
  • 2020-12-08 16:05

    There is no difference.

    unsigned int = uint32 = uint32_t = unsigned in your case and unsigned int = unsigned always

    0 讨论(0)
提交回复
热议问题