A question on the DWORD data type

Started by
8 comments, last by Emmanuel Deloget 17 years, 10 months ago
From googling I found that DWORD has two distinct meanings. One is that it is a "double word" able to hold 32 bits of data, and the other states that DWORD is a typedef for an unsigned long. And since I am going into DirectX/Win32, I just wanted to know if it was right to assume DWORD as a unsigned long. Sorry if this is an utterly stupid question, but somebody has to ask. -Thanks
Advertisement
Both; on most systems an unsigned long is 32 bits. You should find that sizeof(DWORD) == 4.
I do believe that, in the Win32 API, 'DWORD' is a 'typedef' for 'unsigned long'. But when you deal with 'DWORD' in ASM, I believe it's a "double word". Or maybe "unsigned long" is equivelant to "double word"?

I don't know for sure. That's my guess though. I am pretty sure about the typedef'ed 'DWORD', though.
:==-_ Why don't the voices just leave me alone?! _-==:
Oh ok, thanks!

I wanted to assume the two meanings were associated with one another, but my doubt kills me every time.
Quote:Original post by TFS_Waldo
in ASM, I believe it's a "double word"


i think that goes for windows too, because a WORD has 16 bits ( unsigned short if i remember correct^^ ) wich is exactly half of DWORD with 32 bits.

In the strict sense a DWORD is only a double word on 16-bit machines (which is where it was first used). A 'word' is the smallest amount of addressible memory which works out to be the bitness of your processor. 32-bit processors have a word size of 32-bits since a 32-bit processor cant address less than 32 bits.

That being said, a DWORD will always be 32 bits.
Quote:
MSDN officially says
32-bit unsigned integer.

This type is declared in WinDef.h as follows:

typedef unsigned long DWORD;
The link in my post got erased. Here it is again:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/windows_data_types.asp
Quote:Original post by Anonymous Poster
Quote:
MSDN officially says
32-bit unsigned integer.

This type is declared in WinDef.h as follows:

typedef unsigned long DWORD;


They're only somewhat right. It really depends on the compiler's own implementation of long, but usually long equals a 32 bit integer (it does in msvc, gcc and bcc so it's safe to say yes in that matter if you're using one of those).
Killers don't end up in jailThey end up on a high-score!
Quote:Original post by nife
Quote:Original post by Anonymous Poster
Quote:
MSDN officially says
32-bit unsigned integer.

This type is declared in WinDef.h as follows:

typedef unsigned long DWORD;


They're only somewhat right. It really depends on the compiler's own implementation of long, but usually long equals a 32 bit integer (it does in msvc, gcc and bcc so it's safe to say yes in that matter if you're using one of those).


No, they are totally right. If the MS doc says that a DWORD is a 32 bit unsigned integer then it IS a 32 bit unsigned integer. The implementation of a DWORD may vary (it may depend on the compiler), but it still have to obbey to the base definition.

Regards,

This topic is closed to new replies.

Advertisement