C++ 不同整数类型的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11786113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between different integer types
提问by user1507133
I was wondering what is the difference between uint32_t
and uint32
, and when I looked in the header files it had this:
我想知道uint32_t
and之间有什么区别uint32
,当我查看头文件时,它有这个:
types.h:
/** @brief 32-bit unsigned integer. */
typedef unsigned int uint32;
stdint.h:
typedef unsigned uint32_t;
This only leads to more questions: What is the difference between
这只会引出更多问题:两者之间有什么区别?
unsigned varName;
and
和
unsigned int varName;
?
?
I am using MinGW.
我在用 MinGW.
采纳答案by Kerrek SB
unsigned
and unsigned int
are synonymous, much like unsigned short [int]
and unsigned long [int]
.
unsigned
andunsigned int
是同义词,很像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.
uint32_t
是由 C 标准(可选)定义的类型。uint32
只是你编造的一个名字,尽管它恰好被定义为同一个东西。
回答by RiaD
There is no difference.
没有区别。
unsigned int = uint32 = uint32_t = unsigned
in your case and unsigned int = unsigned
always
unsigned int = uint32 = uint32_t = unsigned
在你的情况下,unsigned int = unsigned
总是
回答by Mat
There is absolutely no difference between unsigned
and unsigned int
.
unsigned
和之间绝对没有区别unsigned int
。
Whether that type is a good match for uint32_t
is implementation-dependant though; an int
could be "shorter" than 32 bits.
不过,该类型是否适合匹配uint32_t
取决于实现;anint
可能比 32 位“短”。
回答by Russell Borogove
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.
unsigned
并且unsigned int
由于历史原因是同义词;它们都表示“CPU 架构/平台最自然大小的无符号整数”,在现代平台上通常(但绝不总是)32 位。
<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.
<stdint.h>
是 C99 中的标准头文件,它应该为具有uint32_t
命名约定的特定大小的整数提供类型定义。
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.
该<types.h>
说你看似乎是不规范的,想必是属于一些框架您的项目使用。它的uint32
typedef 与uint32_t
. 您是否应该在代码中使用其中一种是您的经理的问题。