0

根据microsoft HIWORD宏从指定的32 位值中检索高位字。

宏的原始定义是:

#define HIWORD(l)  ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff))

例如,如果传递的参数是一个unsigned long0x12345678,则返回结果是0x1234

重写宏如下:

#define MYHIWORD(l) ((WORD)(((DWORD_PTR)(l)) >> 16))

返回的结果是相同的值0x1234

我的问题:

  • 当传递相同的参数时,为什么两个宏都返回相同的结果?

  • 第一个宏中AND操作(& 0xffff)的目的是什么?

4

1 回答 1

1

What is purpose of AND operation (& 0xffff) in first macro ?

It's not necessary, as the cast will eliminate the high-order bits. I guess it's just there to highlight (to the reader) the fact that bits are being removed.

于 2013-07-07T14:52:16.043 回答