2.62 判断机器是否进行算数右移
//csapp 2.62
#include <stdio.h>
//算数右移返回1,否则返回0
int int_shifts_are_arithmetic()
{
//return !~(-1>>1);
unsigned int w = sizeof(int)<<3;
return !~(1<<(w-1)>>(w-1));
}
int main(void)
{
printf("expect:1, result:%d\r\n", int_shifts_are_arithmetic());
}
邮箱:quiet_learn@163.com
本文版权归作者和博客园共有,欢迎转载,转载请在文章明显位置注明作者及出处,谢谢!