C++ unsigned long 和 UINT64 的区别

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

The difference between unsigned long and UINT64

c++cwindows

提问by Liran

What is the difference between unsigned longand UINT64? I think they are the same, but I'm not sure. The definition of UINT64is :

unsigned long和 和有UINT64什么区别?我认为它们是相同的,但我不确定。的定义UINT64是:

typedef unsigned __int64    UINT64

(by using StdAfx.h)

(通过使用 StdAfx.h)

采纳答案by Jason Coco

UINT64 is specific and declares your intent. You want a type that is an unsigned integer that is exactly 64 bits wide. That this may be equal to an unsigned long on some platforms is coincidence.

UINT64 是特定的并声明您的意图。您需要一个正好为 64 位宽的无符号整数类型。在某些平台上这可能等于 unsigned long 是巧合。

回答by Stephen Ierodiaconou

The unsigned longtype size could change depending on the architecture of the system you are on, while the assumption is that UINT64is definitely 64 bits wide. Have a look at http://en.wikipedia.org/wiki/C_variable_types_and_declarations#Size

unsigned long类型的大小可以根据系统你在的架构改变,而假设是,UINT64绝对是64个位宽。看看http://en.wikipedia.org/wiki/C_variable_types_and_declarations#Size

回答by David Rodríguez - dribeas

The C++ standard does not define the sizes of each of the types (besides char), so the size of unsigned longis implementation defined. In most cases I know of, though, unsigned longis an unsigned 32 bit type, while UINT64(which is an implementation type, not even mentioned in the standard) is a 64 bit unsigned integer in VS.

C++ 标准没有定义每个类型char的大小(除了),所以 的大小unsigned long是实现定义的。不过,在大多数情况下,我知道的unsigned long是 32 位无符号类型,而UINT64(这是一种实现类型,标准中甚至没有提到)是 VS 中的 64 位无符号整数。

回答by M. Williams

See http://msdn.microsoft.com/en-us/library/s3f49ktz(VS.90).aspx

请参阅http://msdn.microsoft.com/en-us/library/s3f49ktz(VS.90).aspx

You want to see the difference between unsigned longand unsigned __int64.

你想看到的区别unsigned longunsigned __int64

回答by Sjoerd

A long is typically 32 bits (but this may very per architecture) and an uint64 is always 64 bits. A native data type which is sometimes 64 bits long is a long long int.

long 通常为 32 位(但这可能非常适合每个架构),而 uint64 始终为 64 位。有时为 64 位长的本机数据类型是long long int.