的,我注意到一些奇怪的行为与支架Bitshifts抵消,而不是预期的行为
bitshifting#include <stdio.h>
int main(void)
{
unsigned char c;
unsigned char d;
c = 153;
c = (c << 7) >> 7;
printf("%d\n", c);
d = 153;
d = (d << 7);
d = (d >> 7);
printf("%d\n", d);
}
输出:
153
1
我预计c
也有1 ...值怎么回事上?这是不确定的?
看看生成的代码以及它的功能。 –
与[this]类似(https://stackoverflow.com/questions/33068985/sizeof-an-integer-expression-in-c)问题。表达式被评估为一个整数,然后存储为char。与中间步骤中的字符对比。 – matt
没问题,lemmi只能使用类型转换 –