64 位 Windows API:C/C++“DWORD”的大小是多少?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4989928/
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
64-bit Windows API: what is the size of a C/C++ "DWORD"?
提问by Stéphane
I only have 32-bit Windows installed, so I cannot verify this myself.
我只安装了 32 位 Windows,所以我无法自己验证。
If I understand correctly, the DWORD used in various places in the Microsoft API is in reference to the original 16-bit word, and has nothing to do with the current hardware architecture?
如果我理解正确,Microsoft API 中各处使用的DWORD 是参考了原来的16 位字,与当前的硬件架构无关?
So DWORD which seems to be 32 bits, will remain 32 bits even when I eventually compile and link my app to run in 64-bit Windows? Or will DWORD become 128 bits wide?
因此,即使我最终编译并链接我的应用程序以在 64 位 Windows 中运行,似乎是 32 位的 DWORD 仍将是 32 位吗?还是 DWORD 会变成 128 位宽?
回答by David Heffernan
The only thing that changes size between 32 and 64 are pointers. So DWORD stays 32 bits wide.
唯一在 32 和 64 之间改变大小的是指针。所以 DWORD 保持 32 位宽。
Some things are not immediately obviously pointers, e.g. HANDLE, LPARAM, WPARAM. But these three change width as they actually hold pointers.
有些东西不是立即明显的指针,例如HANDLE、LPARAM、WPARAM。但是这三个改变宽度,因为它们实际上持有指针。
回答by user541686
Oh God, here comes another reasonable question... :)
哦上帝,这是另一个合理的问题...... :)
It's always 32 bits, since a "word" is considered to be 16 bits in x86. Programs would break if the size changed.
它总是 32 位,因为“字”在 x86 中被认为是 16 位。如果大小改变,程序就会中断。
If you need a native-size DWORD
, try DWORD_PTR
.
如果您需要本机大小DWORD
,请尝试DWORD_PTR
.
(Don't askwhat the difference between DWORD_PTR
, ULONG_PTR
, UINT_PTR
, and size_t
is; I have no ideawhat Microsoft was thinking when it invented the first three...)
(不要问DWORD_PTR
, ULONG_PTR
, UINT_PTR
, 和size_t
is之间的区别是什么;我不知道微软在发明前三个时是怎么想的......)
回答by xanatos
DWORD is always 32 bits (unsigned). QWORD is always 64 bits (unsigned). Then there are the DWORD32 and a DWORD64 that are 32 and 64 bits. Don't ask me why are they there :-)
DWORD 总是 32 位(无符号)。QWORD 始终为 64 位(无符号)。然后是 32 位和 64 位的 DWORD32 和 DWORD64。不要问我他们为什么在那里:-)
http://msdn.microsoft.com/en-us/library/cc230318(v=PROT.10).aspx
http://msdn.microsoft.com/en-us/library/cc230318(v=PROT.10).aspx
http://msdn.microsoft.com/en-us/library/cc230362(v=PROT.10).aspx
http://msdn.microsoft.com/en-us/library/cc230362(v=PROT.10).aspx
and in general
一般来说
http://msdn.microsoft.com/en-us/library/cc230309(v=PROT.10).aspx
http://msdn.microsoft.com/en-us/library/cc230309(v=PROT.10).aspx
回答by hjorgan
I would even go further than x86 arch. and say in general, a WORD may be considered to be 16 bits. The hierarchy traditionally has been BYTE (8 bits), WORD (16 BITS), and so a DWORD (if D is taken to be a double wide WORD) would be 32 bits. This doesn't necessarily have anything to do with a particular platform or language, a BYTE has been 8 bits and a WORD has been 16 bits going back to the old 8 bit computer days, even before the x86 arch. existed
我什至会比 x86 arch 走得更远。并且一般来说,一个 WORD 可以被认为是 16 位。传统上的层次结构是 BYTE(8 位)、WORD(16 位),因此 DWORD(如果 D 被视为双宽 WORD)将是 32 位。这不一定与特定平台或语言有关,BYTE 是 8 位,而 WORD 是 16 位,可以追溯到旧的 8 位计算机时代,甚至在 x86 架构之前。存在
回答by Ted Hopp
On x86 processors, a DWORD is 32 bits, even on 64-bit Windows. See this Wikipedia article.
在 x86 处理器上,DWORD 是 32 位,即使在 64 位 Windows 上也是如此。请参阅这篇维基百科文章。