_bittestandreset、_bittestandreset64

Microsoft 专用

生成一个指令,该指令可以检查地址 a 的位 b,返回其当前值,然后将位设置为 0。

语法

unsigned char _bittestandreset(
   long *a,
   long b
);
unsigned char _bittestandreset64(
   __int64 *a,
   __int64 b
);

参数

a
[in, out] 指向要检查的内存的指针。

b
[in] 要测试的位位置。

返回值

指定位置的位。

要求

Intrinsic 体系结构
_bittestandreset x86、ARM、x64、ARM64
_bittestandreset64 x64、ARM64

头文件<intrin.h>

备注

此例程仅可用作内部函数。

示例

// bittestandreset.cpp
// processor: x86, IPF, x64
#include <stdio.h>
#include <limits.h>
#include <intrin.h>

#pragma intrinsic(_bittestandreset)

// Check the sign bit and reset to 0 (taking the absolute value)
// Returns 0 if the number is positive or zero
// Returns 1 if the number is negative
unsigned char absolute_value(long* p)
{
   const int SIGN_BIT = 31;
   return _bittestandreset(p, SIGN_BIT);
}

int main()
{
    long i = -112;
    unsigned char result;

    // Check the sign bit and reset to 0 (taking the absolute value)

    result = absolute_value(&i);
    if (result == 1)
        printf_s("The number was negative.\n");
}
The number was negative.

结束 Microsoft 专用

另请参阅

编译器内部函数