70,020
社区成员




#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
unsigned char a = 0;
std::cout << (a-1) << std::endl;
while(1){};
return 0;
}
VS2012编译出来是-1
char - int ,char会被强转成int 还是说unsigned char 本身可能就是int型的?
int _tmain(int argc, _TCHAR* argv[])
{
003A1370 push ebp
003A1371 mov ebp,esp
003A1373 sub esp,0CCh
003A1379 push ebx
003A137A push esi
003A137B push edi
003A137C lea edi,[ebp-0CCh]
003A1382 mov ecx,33h
003A1387 mov eax,0CCCCCCCCh
003A138C rep stos dword ptr es:[edi]
unsigned char a = 0;
003A138E mov byte ptr [a],0
a - 1;
return 0;
003A1392 xor eax,eax
}
unsigned char a = 0;
int i = a - 1;
a = 0;
unsigned int ii = a -1;
a = 0;
unsigned char b = a - 1;
这个是汇编代码,VC2008SP1
unsigned char a = 0;
0122138E mov byte ptr [a],0
int i = a - 1;
01221392 movzx eax,byte ptr [a]
01221396 sub eax,1
01221399 mov dword ptr [i],eax
a = 0;
0122139C mov byte ptr [a],0
unsigned int ii = a -1;
012213A0 movzx eax,byte ptr [a]
012213A4 sub eax,1
012213A7 mov dword ptr [ii],eax
a = 0;
012213AA mov byte ptr [a],0
unsigned char b = a - 1;
012213AE movzx eax,byte ptr [a]
012213B2 sub eax,1
012213B5 mov byte ptr [b],al