I've come into contact with some weird notation in a C++ program. I'm dealing with bit shifting and I came across the LOWORD() and HIWORD() functions. I understand that LOWORD is the value of the lower 2 bytes of an integer. I also know that HIWORD is the higher 2 byes of that integer. However, I came into contact with a code snippet which looked something like this:
#define LOWORD(l) ((WORD)(((DWORD_PTR)(l)) & 0xffff))
#define HIWORD(l) ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff))
int v1 = 0x12343460;
int v2 = 0x11111111;
HIWORD(v2) = HIWORD(v1);
LOWORD(v1) = LOWORD(v2);
From what it appears, it looks as though the programmer is suggesting to place the value of one function into another function. However, that seems impossible without some serious programmer magic. Any help whatsoever in decrypting this code snippet would be greatly appreciated.
To fix it:
#define HIDWORD(dw, hw) LOWORD(dw) | (hw << 16)
#define LODWORD(dw, lw) (HIWORD(dw) << 16) | lw
-----------------------------------------------
v2 = HIDWORD(v2, HIWORD(v1));
v1 = LODWORD(v1, LOWORD(v2));