26

我想知道 和 之间有什么区别uint32_tuint32当我查看头文件时,它有:

types.h:

    /** @brief 32-bit unsigned integer. */
    typedef unsigned int uint32;
stdint.h:

    typedef unsigned   uint32_t;

这只会引出更多问题:两者有什么区别?

unsigned varName;

unsigned int varName;

?

我在用MinGW.

4

4 回答 4

22

unsignedandunsigned int是同义词,很像unsigned short [int]and unsigned long [int]

uint32_t是由 C 标准(可选)定义的类型。uint32只是你编的一个名字,虽然它恰好被定义为同一个东西。

于 2012-08-02T21:38:36.437 回答
5

没有区别。

unsigned int = uint32 = uint32_t = unsigned在你的情况下,unsigned int = unsigned总是

于 2012-08-02T21:35:31.400 回答
3

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.

于 2012-08-02T21:40:14.980 回答
2

unsigned和之间绝对没有区别unsigned int

但是,该类型是否适合匹配uint32_t取决于实现;anint可能比 32 位“更短”。

于 2012-08-02T21:35:24.013 回答