关于Linux下C编译错误(警告)cast from 'void*' to 'int' loses precision
2014-11-29 14:37
405 查看
放上博主出错的代码:
char *ptr; //此后省略部分代码
if( (int)ptr==-1 ) //出错地方
那句话的意思是从 void* 到 int 的转换丢失精度,相信看到解释有些人就明白了,
此问题只会出现在X64位的Linux上,因为在64位的机器上指针占用8个字节,int 占用四个字节,所以才会出现这样的问题,
解决方法:
(long)ptr == -1 就好了
char *ptr; //此后省略部分代码
if( (int)ptr==-1 ) //出错地方
那句话的意思是从 void* 到 int 的转换丢失精度,相信看到解释有些人就明白了,
此问题只会出现在X64位的Linux上,因为在64位的机器上指针占用8个字节,int 占用四个字节,所以才会出现这样的问题,
解决方法:
(long)ptr == -1 就好了
相关文章推荐
- 关于Linux下C编译错误(警告)cast from 'void*' to 'int' loses precision
- 关于Linux下C编译错误(警告)cast from 'void*' to 'int' loses precision
- ndk-build编译64位.so,出现ndk error: cast from 'int*' to 'int' loses precision [-fpermissive]
- Linux系统平台下关于GCC编译及使用的方法(-Werror,它要求GCC将所有的警告当成错误进行处理 )
- Linux系统平台下关于GCC编译及使用的方法 (-Werror,它要求GCC将所有的警告当成错误进行处理
- iOS 当用到第三方的文件的时候,警告 implicit conversion loses integer precision:'long' to 'int '
- x86_64 xercexc: error: cast from 'const void*' to 'long int' loses precision [-fpermissive]
- cast from 'void *' to 'int' loses precision
- 关于Linux环境编译错误:“undefined reference to" 的原因总结
- 关于Linux驱动的一种错误:Unable to handle kernel paging request at virtual address
- error: cast from ‘char*’ to ‘int’ loses precision
- Linux编译警告:检测到时钟错误。您的创建可能是不完整的。
- 关于arm-linux-gcc交叉编译工具链,实现自己的crt0或者编译UBOOT出现undefined reference to `__aeabi_unwind_cpp_pr0'的解决方法
- G++编译错误 no matching function for call to '_tag_data_value::StringAddLen(std::string, int, int)
- Linux系统平台下关于GCC编译及使用的方法(-Werror,它要求GCC将所有的警告当成错误进行处理 )
- Xcode错误"Cast from pointer to smaller type 'int' loses information”
- 关于编译Lambda时报告返回的为void的错误
- gcc编译错误(invalid conversion from 'int' to enum)
- Linux GCC编译警告:Clock skew detected. 错误解决办法
- 关于Amdroid 4.0编译生成Recovery的一个错误:ValueError: too many values to unpack