error: cast from ‘char*’ to ‘int’ loses precision

程序:

char* addrCom; 
addrCom= ......//赋值 
if(-1 == (int)addrCom) //导致编译出错 
{ ...... } 

编译时出现错误:

 error: cast fromchar*’ to ‘int’ loses precision

因为我编译的系统为linux64位,其指针类型和long型大小相等(8B)而与int型4B,故会出现:loses precision。故:先将char*-->long,然后从long到int自动隐式转换。

将(int)addrCom 改为(long)addrCom

       

转载于:https://www.cnblogs.com/xiaojianliu/p/9742328.html

你可能感兴趣的:(error: cast from ‘char*’ to ‘int’ loses precision)