C++ DWORD 格式说明符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33671758/
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
DWORD format specifier
提问by
This is a follow up question to this.
这是this的后续问题。
Can it be that DWORD
is sameas int
on some platform(How to check this?)? If that is the case, then this:
它可以是DWORD
是相同的int
一些平台(该如何检查?)?如果是这样的话,那么这个:
DWORD v1, v2, v3, Build;
GetVersion(&v1, &v2, &v3, &Build);
sprintf(VersionStr, "%d.%d.%d.%d", v1, v2, v3, Build);
is not undefined behaviour on that platform, am I right??
在那个平台上不是未定义的行为,对吗?
Or above code is ALWAYS and everywhere UB?
或者上面的代码总是和无处不在的UB?
How to check whether DWORD
is same as int
on that platform?
如何检查是否DWORD
与int
该平台上的相同?
(because maybe I am thinking on that computer where this code is run above is not undefined behaviour)
(因为也许我在想在上面运行此代码的那台计算机上不是未定义的行为)
回答by Rahul Tripathi
On a 32 bit compiler, the format specifier which you can use to print the value of DWORD is %lu
. You can also use %ld
if you want to print the value in decimal format.
在 32 位编译器上,可用于打印 DWORD 值的格式说明符是%lu
. %ld
如果要以十进制格式打印值,也可以使用。
You can also refer a thread: Why in C++ do we use DWORD rather than unsigned int?
您还可以参考一个线程:为什么在 C++ 中我们使用 DWORD 而不是 unsigned int?