_BitScanReverse returns 索引为 1 时为 0,表示根据 MS "no set bits were found"

_BitScanReverse returns 0 when index is 1 which means according to MS "no set bits were found"

直接从 MSDN 复制...

unsigned char _BitScanReverse(  
   unsigned long * Index,  
   unsigned long Mask  
);  

描述

从最高有效位 (MSB) 到最低有效位 (LSB) 搜索设置位 (1) 的掩码数据。

Return 值

如果设置了索引则为非零,如果未找到设置位则为 0

根据 return 值描述,如果未找到设置位,则索引 = 0。但是在 mask = 1 的情况下会发生什么? 运行 MSDN 文档中的指令附带的示例代码,它 return 也是 0,这让程序员感到困惑,因为他不知道是 "no set bit were found" 还是 "index equals to 1" .

我是不是理解错了?

您误读了文档。 return 值 为 1 或 0,具体取决于 mask 中是否有非零位。设置位的索引是 returned in *Index。不会引起混淆。