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());
}
posted @ 2020-05-10 19:21  铵铵静静  阅读(150)  评论(0编辑  收藏  举报