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

Posted xiaojianliu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

       

以上是关于error: cast from ‘char*’ to ‘int’ loses precision的主要内容,如果未能解决你的问题,请参考以下文章

warning: assignment makes pointer from integer without a cast

关于Linux下C编译错误(警告)cast from 'void*' to 'int' loses precision

error C2664: 'strcpy' : cannot convert parameter 2 from 'LPCTSTR' to 'const char

类型收窄 error C2397: conversion from ‘const int‘ to ‘char‘ requires a narrowing conversion

SQL Casting datetime 并将其用于 groupby

reinterpret_cast 在 char* 指针上