error: cast from ‘char*’ to ‘int’ loses precision
来源:互联网 发布:中天数据恢复 编辑:程序博客网 时间:2024/04/29 12:30
编译时出现错误:
error: cast from ‘char*’ to ‘int’ loses precision
原因:程序中存在
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 ‘void*’ to ‘int’ loses precision
- cast from 'void *' to 'int' loses precision
- x86_64 xercexc: error: cast from 'const void*' to 'long int' loses precision [-fpermissive]
- ndk-build编译64位.so,出现ndk error: cast from 'int*' to 'int' loses precision [-fpermissive]
- 关于Linux下C编译错误(警告)cast from 'void*' to 'int' loses precision
- 关于Linux下C编译错误(警告)cast from 'void*' to 'int' loses precision
- 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解决方案
- Cast from pointer to smaller type 'int' loses
- xcode更新到5.1,"Cast from pointer to smaller type 'int' loses information” in EAGLView.mm
- 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更新到5.1,"Cast from pointer to smaller type 'int' loses information” in EAGLView.mm
- Xcode错误"Cast from pointer to smaller type 'int' loses information”
- iOS开发 - "Cast from pointer to smaller type 'int' loses information” 解决办法
- Iterator 的一般用法
- AMD+WIN7+VMware安装MAC OS X 10.6.3 和 Xcode 3.2.2
- sqlserver查询表空间大小,使用大小,数据条数
- timing verification--Half-Cycle Paths
- PHP手册 第 28 章 数据库安全
- error: cast from ‘char*’ to ‘int’ loses precision
- 深入理解Linux内核个人小结1---绪论
- 申请Android Map API Key .
- javascript传递参数给cgi
- android的各种*.img 文件
- struts-1.3.10中的<action-mappings> <action>标签中<set-property>的用法
- BASH SHELL 接受参数
- The Pensive Programmer
- Storm源码浅析之topology的提交