tags:

views:

104

answers:

6

hi everyone is any one knows whats the diffrence between unsigned long to UINT64 i think its the same , but im not sure. the defenition of UINT64 is : typedef unsigned __int64 UINT64 (By Using StdAfx.h)

thanks.

+2  A: 

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.

Jason Coco
Specific as long as it is defined, and non-portable....
njsf
A: 

The built-in long type can vary according to platform. On a 32-bit platform like Windows, a long will be 64 bits, but you cannot assume that this will be the case on other platforms.

UINT64 is always guaranteed to be 64 bits.

Jen
UINT64 is not guaranteed to always be 64 bits in all platforms since UINT64 is not guaranteed to be defined in the C standard. See http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1336.pdf ( * Draft of the C99 standard with corrigenda TC1, TC2, and TC3 included ) you will find no UINT64 reference...
njsf
I always thought it was defined in stdlib.h?
Jen
"On ... Windows, a long will be 64 bits". Did you mean 32 bits here?
Mark Dickinson
@MarkDickinson Indeed: "While int and long data types remain 32 bits on 64-bit Microsoft Windows running on AMD64 platforms" (pag 9) http://download.microsoft.com/download/5/b/5/5b5bec17-ea71-4653-9539-204a672f11cf/MMCodec_amd64.doc
njsf
+1  A: 

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

Steve
+1  A: 

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

You want to see the difference between unsigned long and unsigned __int64.

Kotti
+1  A: 

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.

Sjoerd
+1  A: 

The C++ standard does not define the sizes of each of the types (besides char), so the size of unsigned long is implementation defined. In most cases I know of, though, unsigned long is 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.

David Rodríguez - dribeas
The standard doesn't define the size of `char` either, it's implementation defined using CHAR_BITS in limits.h.
paxdiablo
You are right in §5.3.3/1 The result of `sizeof` is defined as the size in bytes of the argument, and at the same time it defines `sizeof(char)` to be `1`, which means that the size of `char` is one byte. But the size of a byte is not defined in the standard. In §1.7/1 it only says that it must be a contiguous sequence of bits, the number of which is undefined.
David Rodríguez - dribeas
The standard defines the *minimum* sizes of the types (though it defines it in terms of the minimum ranges). For `char`, `short`, `int`, `long` and `long long` those minima are 8, 16, 16, 32 and 64 bits respectively. (By the way, it's `CHAR_BIT` - no S).
caf
@caf: The current c++ standard does not define those minima at all. The C++0x Final Draft requires chars to be at least 8bit, but it does not require any minimal size for any other type, only a partial order. Are you referring to the C standard? (BTW, I have updated the answer to make explicit that it refers to the C++ standard, and not C)
David Rodríguez - dribeas
They are in the C standard (in C99, §5.2.4.2.1). This section of the ISO C standard is included in C++ standard by reference.
caf
The current standard does not refer to C99, but rather to C89 (ISO/IEC 9899:1990), and within the C++ standard the size of the different integer types is basically undefined only a partial order is required, `char` is 1 byte, `int` must be able to hold [INT_MIN,INT_MAX] as defined in `climits`. the type `long long` does not even exist in the current C++ standard (it will in C++0x)
David Rodríguez - dribeas