RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

WORD, DWORD vs. short and int

Kamron

Knight
I could be wrong (Zippy?) in my experience they have been interchangable. Maybe its only for referencing (compatibility) purposes.

For COM and dlls I use DWORD if its a non C# library.
 

Sep102

Page
There isn't a reason that they have to be used or anything of the sort. They're used for essentially two reasons:
  • That using them expresses the intent of the value better (for example, this parameter isn't meant to be a number, but a certain bit sequence [in the case of a WORD/DWORD] or this is meant to be a pointer to a sequence of values in memory [that could be anything; in the case of a WORD */DWORD *]).
  • That using them allows your code to be more easily ported to different architectures with different sizes for WORD's/DWORD's (which, of course, is likely something that's never going to happen with an average programmer's code, but it is a possibility nonetheless).

But, I basically just lied, they're mostly used because people see them in Microsoft's example code, in the tutorials for the WIN32 API, in the headers and in Intellisense™, so people use them just in case or to be consistent (or, once in a blue moon, for the bullets above).

And, they are interchangeable in general, but it's still a better idea to use the API's types when working with it (if just for consistency, assurance of correct types or superstition).
 

gilgamash

Knight
Main purpose: Different bit lengths => different intervals of numbers

The main usage of those things is to make clear the sequence WORD - DWORD - QWORD etc. The BIG problem is the inconsistency in their amount of bits due to the lack of standardization. This especially poses a problem presently when switching from 32bit to 64bit systems. Take any 32bit linux proggy that for instance wrote some integers to a binary file using the sizeof(int) operator. Reread the file with the code compiled on a 64bit system - BANG!

Advise here: use cstdint or sys/inttypes headder with standardized widths (such as uint16_t, int64_t etc.)
 
Top