C++ 具有 32 位和 64 位代码的 DWORD 有多大?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39419/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 12:23:59  来源:igfitidea点击:

How large is a DWORD with 32- and 64-bit code?

c++winapi64-bitdword

提问by Haim Bender

In Visual C++ a DWORD is just an unsigned long that is machine, platform, and SDK dependent. However, since DWORD is a double word (that is 2 * 16), is a DWORD still 32-bit on 64-bit architectures?

在 Visual C++ 中,DWORD 只是一个与机器、平台和 SDK 相关的无符号长整型。但是,由于 DWORD 是一个双字(即 2 * 16),在 64 位体系结构上 DWORD 仍然是 32 位吗?

回答by Nir

Actually, on 32-bit computers a word is 32-bit, but the DWORD type is a leftover from the good old days of 16-bit.

实际上,在 32 位计算机上,一个字是 32 位的,但 DWORD 类型是 16 位过去美好时光的遗留物。

In order to make it easier to port programs to the newer system, Microsoft has decided all the old types will not change size.

为了更容易地将程序移植到新系统,微软决定所有旧类型不会改变大小。

You can find the official list here: http://msdn.microsoft.com/en-us/library/aa383751(VS.85).aspx

您可以在此处找到官方列表:http: //msdn.microsoft.com/en-us/library/aa383751(VS.85).aspx

All the platform-dependent types that changed with the transition from 32-bit to 64-bit end with _PTR (DWORD_PTR will be 32-bit on 32-bit Windows and 64-bit on 64-bit Windows).

随着从 32 位到 64 位转换而改变的所有平台相关类型都以 _PTR 结尾(DWORD_PTR 在 32 位 Windows 上为 32 位,在 64 位 Windows 上为 64 位)。

回答by Mark Ingram

It is defined as:

它被定义为:

typedef unsigned long       DWORD;

However, according to the MSDN:

但是,根据 MSDN:

On 32-bit platforms, long is synonymous with int.

在 32 位平台上,long 与 int 同义。

Therefore, DWORD is 32bit on a 32bit operating system. There is a separate define for a 64bit DWORD:

因此,DWORD 在 32 位操作系统上是 32 位。64 位 DWORD 有一个单独的定义:

typdef unsigned _int64 DWORD64;

Hope that helps.

希望有帮助。

回答by Rob Walker

No ... on all Windows platforms DWORD is 32 bits. LONGLONG or LONG64 is used for 64 bit types.

不...在所有 Windows 平台上,DWORD 是 32 位。LONGLONG 或 LONG64 用于 64 位类型。