error: cast from ‘char*’ to ‘int’ loses precision
2017-12-28 22:18
3059 查看
编译时出现错误:
error: cast from ‘char*’ to ‘int’ loses precision
原因:程序中存在
[cpp] view
plain copy
char* addrCom;
addrCom= ......//赋值
if(-1 == (int)addrCom) //导致编译出错
{ ...... }
上面是隐式转换,将其改为标准C++显示类型转换:static_cast<int>或这是reinterpret_cast<int>
依然是:
error: cast from ‘char*’ to ‘int’ loses precision
最后google了一下,找到了答案:http://stackoverflow.com/questions/1640423/error-cast-from-void-to-int-loses-precision
应该将(int)addrCom 改为(long)addrCom即可
解释:
因为我编译的系统为linux64位,其指针类型和long型大小相等(8B)而与int型4B,故会出现:loses precision。
故:先将char*-->long,然后从long到int自动隐式转换。
error: cast from ‘char*’ to ‘int’ loses precision
原因:程序中存在
[cpp] view
plain copy
char* addrCom;
addrCom= ......//赋值
if(-1 == (int)addrCom) //导致编译出错
{ ...... }
上面是隐式转换,将其改为标准C++显示类型转换:static_cast<int>或这是reinterpret_cast<int>
依然是:
error: cast from ‘char*’ to ‘int’ loses precision
最后google了一下,找到了答案:http://stackoverflow.com/questions/1640423/error-cast-from-void-to-int-loses-precision
应该将(int)addrCom 改为(long)addrCom即可
解释:
因为我编译的系统为linux64位,其指针类型和long型大小相等(8B)而与int型4B,故会出现:loses precision。
故:先将char*-->long,然后从long到int自动隐式转换。
相关文章推荐
- error: cast from ‘char*’ to ‘int’ loses precision
- error: cast from ‘char*’ to ‘int’ loses precision
- error: cast from ‘char*’ to ‘int’ loses precision
- x86_64 xercexc: error: cast from 'const void*' to 'long int' loses precision [-fpermissive]
- error: cast from ‘void*’ to ‘int’ loses precision
- cast from 'void *' to 'int' loses precision
- Xcode更新到5.1,"Cast from pointer to smaller type 'int' loses information” in EAGLView.mm
- iOS开发 - "Cast from pointer to smaller type 'int' loses information” 解决的方法
- Xcode错误"Cast from pointer to smaller type 'int' loses information”
- ndk-build编译64位.so,出现ndk error: cast from 'int*' to 'int' loses precision [-fpermissive]
- iOS开发 - "Cast from pointer to smaller type 'int' loses information” 解决办法
- "Cast from pointer to smaller type 'int' loses information” 解决
- xcode更新到5.1,"Cast from pointer to smaller type 'int' loses information” in EAGLView.mm
- Cast from pointer to smaller type 'int' loses information
- Cast from pointer to smaller type 'int' loses information解决方案
- Cast from pointer to smaller type 'int' loses information
- iOS开发 - "Cast from pointer to smaller type 'int' loses information” 解决办法
- error: invalid cast from type _gnu_cxx::__normal_iterator<> to unsigned char*
- iOS开发 - "Cast from pointer to smaller type 'int' loses information” 解决办法
- xcode更新到5.1,"Cast from pointer to smaller type 'int' loses information” in EAGLView.mm