PDA

View Full Version : What does "Force DWORD" mean?



chronozphere
22-02-2008, 05:17 PM
Hi everyone

I'm looking at the code for HGE (Game engine) and i noticed this:


THGEIntState = (
HGE_SCREENWIDTH = 9, // int screen width (default: 800)
HGE_SCREENHEIGHT = 10, // int screen height (default: 600)
HGE_SCREENBPP = 11, // int screen bitdepth (default: 32) (desktop bpp in windowed mode)

HGE_SAMPLERATE = 19, // int sample rate (default: 44100)
HGE_FXVOLUME = 20, // int global fx volume (default: 100)
HGE_MUSVOLUME = 21, // int global music volume (default: 100)

HGE_FPS = 23, // int fixed fps (default: HGEFPS_UNLIMITED)

HGEINTSTATE_FORCE_DWORD = $7FFFFFF
);


Notice the HGEINTSTATE_FORCE_DWORD. What does it do??

I've also seen this in the Direct3d headers. Here is the C++ def for D3DCULL:


typedef enum D3DCULL
{
D3DCULL_NONE = 1,
D3DCULL_CW = 2,
D3DCULL_CCW = 3,
D3DCULL_FORCE_DWORD = 0x7fffffff,
} D3DCULL, *LPD3DCULL;


Can someone explain what FORCE_DWORD is for?

thank you. :)

LP
23-02-2008, 01:11 AM
The value of "Force DWORD" is used as a trick to force the enumeration to occupy 32 bits.

The above example uses values from 9 to 23, so it could be packed in smaller structure (byte, for instance). However, the author wanted the enumaration to be 4 bytes long and thus, an additional very large value was added.

chronozphere
23-02-2008, 10:30 AM
Okay.. so it is used to force the compiler to make every value inside the enum a DWORD.

but why is this neccesary?

JernejL
23-02-2008, 11:06 AM
Okay.. so it is used to force the compiler to make every value inside the enum a DWORD.

but why is this neccesary?

memory alignment?

harrypitfall
23-02-2008, 01:13 PM
Delphi version 7 and above have a compiler diretive to force "memory" alignment... :) but i prefer to use "Consts" and declare THGEIntState = DWORD/Cardinal...

{$Z4} or {$MINENUMSIZE 4} = if an enumerated type is declared in the {
$Z4} state, it is stored as an unsigned double word. (much clean that the force_dword trick)

waran
23-02-2008, 03:47 PM
As far as I know Delphi aligns to dword automatically.

@chronozphere: This is done because the dword is the 32-Bit-CPUs
native size. Accessing a dword is much faster than accessing a smaller
value. Also some Hardware (like the GPU) depends on specially aligned
data, sometimes.

chronozphere
24-02-2008, 03:41 PM
Okay.. thanks for the explanation ;)

arthurprs
26-02-2008, 09:04 PM
As far as I know Delphi aligns to dword automatically.

@chronozphere: This is done because the dword is the 32-Bit-CPUs
native size. Accessing a dword is much faster than accessing a smaller
value. Also some Hardware (like the GPU) depends on specially aligned
data, sometimes.

so its faster to evaluate integers (longbool) them evaluate boolean (byte) ?