Unexpected sign extension of int32 or 32bit pointer when converted to uint64

前端 未结 4 2027
醉话见心
醉话见心 2020-12-19 19:50

I compiled this code using Visual Studio 2010 (cl.exe /W4) as a C file:

int main( int argc, char *argv[] )
{
    unsigned __int64 a = 0x00000000         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-19 20:24

    Use this to avoid the sign extension:

    unsigned __int64 a = 0x00000000FFFFFFFFLL;
    

    Note the L on the end. Without this it is interpreted as a 32-bit signed number (-1) and then cast.

提交回复
热议问题