C++ 什么是 u_int32_t?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5163835/
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
What is u_int32_t?
提问by kevin
Possible Duplicate:
Datatypes used in C
可能的重复:
C 中使用的数据类型
Hi I'm doing porting from Linux to Visual C ++. And I found quite a few errors. What is u_int32_t ? I can't find it in Visual C ++? Is it only available in Linux? Which type should I use in Visual C++? Thanks in advance !!!
嗨,我正在从 Linux 移植到 Visual C++。我发现了很多错误。什么是 u_int32_t ?我在 Visual C++ 中找不到它?它仅在 Linux 中可用吗?我应该在 Visual C++ 中使用哪种类型?提前致谢 !!!
Kevin
凯文
回答by 0xC0000022L
The C99 header stdint.h
defines types that do not depend on architecture or compiler. The meaning of unsigned int can differ (e.g. 16bit wide on a 16bit system), but those types from stdint.h
have a specific size.
C99 头文件stdint.h
定义了不依赖于体系结构或编译器的类型。unsigned int 的含义可能不同(例如,在 16 位系统上为 16 位宽),但这些类型stdint.h
具有特定的大小。
Either the additional underscore accidentally slipped in there, or someone re-typed them for some library or whatever. If the latter one is the case, include some header of your own, in that header include stdint.h
and make sure to typedef uint32_t u_int32_t
after the include.
要么是额外的下划线不小心滑到了那里,要么是有人为某个图书馆或其他东西重新输入了它们。如果是后者,请包含您自己的一些标题,在该标题中包含stdint.h
并确保typedef uint32_t u_int32_t
在包含之后。
回答by Ben Voigt
These not-quite-standard names appear to have been introduced by BSD: http://lists.freedesktop.org/archives/release-wranglers/2004-August/000923.html
这些不太标准的名称似乎是由 BSD 引入的:http: //lists.freedesktop.org/archives/release-wranglers/2004-August/000923.html
回答by Shamim Hafiz
I am not fully sure about the exact type, but based on the name, it looks like an unsigned 32 bit integer. The corresponding type in Visual C++ would be unsigned int.
我不完全确定确切的类型,但根据名称,它看起来像一个无符号的 32 位整数。Visual C++ 中的相应类型将是unsigned int。
There are other Aliases for that, but this name would suffice.
还有其他别名,但这个名字就足够了。
回答by MAK
This is an int
datatype that is unsigned guaranteed to be 32 bits. To use it you need to include the stdint.h.
这是一种int
无符号数据类型,保证为 32 位。要使用它,您需要包含stdint.h。
I am not sure whether this is available directly in the latest version of VC++. The wikipedia page has links to various implementations that work with Microsoft compilers (e.g. msinttypes).
我不确定在最新版本的 VC++ 中是否可以直接使用。维基百科页面提供了与 Microsoft 编译器(例如msinttypes)配合使用的各种实现的链接。
If you are sure that the default unsigned int
type is always going to be 32 bits, you may be able to just substitute unsigned int
in its place. But using an explicit 32 bit datatype is preferable.
如果您确定默认unsigned int
类型始终为 32 位,您可以只替换unsigned int
它的位置。但是最好使用显式的 32 位数据类型。
回答by asveikau
Not sure about u_int32_t
, but uint32_t
is a standard type according to the 1999 version of the C standard, coming from <stdint.h>
.
不确定u_int32_t
,但根据 1999 年版本的 C 标准,它uint32_t
是一种标准类型,来自<stdint.h>
.
Visual C++ has made a choice not to adopt C99, so it is not supported there. If you include <windows.h>
you can just use DWORD
, which will be the same size and also unsigned.
Visual C++ 已选择不采用 C99,因此在那里不受支持。如果包含<windows.h>
,则可以使用DWORD
,它的大小相同且未签名。