加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

从以下代码获取警告“转换为不同大小的整数的指针”

发布时间:2020-12-16 06:04:37 所属栏目:百科 来源:网络整理
导读:代码是: Push(size,(POINTER)(GetCar(i) == term_Null()? 0 : 1)); 这是C代码推送返回ABC typedef POINTER *ABC typedef void * POINTER ABC size; Push(ABC,POINTER); XYZ GetCar(int); typedef struct xyz *XYZ; XYZ term_Null(); long int i; 特定警告的
代码是:
Push(size,(POINTER)(GetCar(i) == term_Null()? 0 : 1));

这是C代码推送返回ABC

typedef POINTER  *ABC
 typedef void * POINTER
 ABC size;
 Push(ABC,POINTER);
 XYZ GetCar(int);
 typedef struct xyz *XYZ;
 XYZ term_Null(); 
 long int i;

特定警告的原因是什么?

解决方法

您可以使用intptr_t来确保整数与指针的宽度相同.这样,您不需要发现有关您的特定平台的东西,它也可以在另一个平台上运行(与unsigned long解决方案不同).
#include <stdint.h>

Push(size,(POINTER)(intptr_t)(GetCar(i) == term_Null()? 0 : 1));

取自C99标准:

7.18.1.4 Integer types capable of holding object pointers

1 The
following type designates a signed
integer type with the property that
any valid pointer to void can be
converted to this type,then converted
back to pointer to void,and the
result will compare equal to the
original pointer:

intptr_t

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读