Advantages of...

Started by
5 comments, last by GOOSEDUMP 22 years, 6 months ago
what are the advantages of using DWORD? I''m looking at a lot of code that use DWORD instead of int/long.... I''m wonderying why? What are the benifits? What are the downfalls? What type of situaion would you want to use a DWORD? Thanks ladies and gents..
Advertisement
A BYTE/WORD/DWORD are always the same size. Size of an int or something is dependent on compile/platform. This will usually not matter, but if you want to write/read from a file 32-bits, you can''t count on int working. For example, if I remember correctly, the ints in a file were 16-bit, and i was reading them as 32-bit values. The program would compile and work at school, but not at home, due to this problem.
I think Microsoft made it up so they could know for a fact how "big" the variable was.

WORD came from 16 bit Windows, and is 16 bits wide.

DWORD is 32 bits wide.

They did this because the size of "int" or "long" isn''t fixed.

As far as I know, someone correct me if I''m wrong please, but ints are guaranteed to be at least 32 bits, and long is guaranteed to be at least as wide as an int.

- Pete
This whole thing bothers me abit. Last time I was programing
I didn''t have DWORD and WORD. I would like to stop typeing out
things like unsigned int but I worried that I might cause some
incompatiblity problem like mentioned before. Oh well. Guess
I could stop being lazy and look it up.
------------------------------------------------------------- neglected projects Lore and The KeepersRandom artwork
int''s aren''t always 32-bits wide, they may also be 16-bits wide (depends on the system), but long''s are always 32-bits wide.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

in "Windef.h"....

typedef unsigned long DWORD;

ie, its a macro...



"It''s only after you''ve lost everything that you''re free to do anything." Tyler Durden
"It's only after you've lost everything that you're free to do anything." Tyler Durden
quote:Original post by _Zerapolis_
in "Windef.h"....

typedef unsigned long DWORD;

ie, its a macro...

Not a macro, a typedef
a macro looks like:

#define DWORD unsigned long

This topic is closed to new replies.

Advertisement