看如下代码(环境为VC6):
#define NUM (unsigned char)0x01
long a = NUM<<17;
printf("%ld",a);
结果输出131072
汇编代码:
#define NUM ((unsigned char)0x01)
32: long a = NUM<<17;
00401268 mov dword ptr [ebp-4],20000h
33: printf("%d",a);
0040126F mov eax,dword ptr [ebp-4]
00401272 push eax
00401273 push offset string "%d" (0043101c)
00401278 call printf (00401520)
0040127D add esp,8
34: return 0;
00401280 xor eax,eax
注意20000h,并不是8bit。编译器处理的时候和运行的时候不一样。
如
unsigned char a = 0x01;
a = a<<9;
printf("%d",a);
输出为0。