获取警告"从不同规模和QUOT的整数转换为指针;从以下code [英] Getting the warning "cast to pointer from integer of different size" from the following code

查看:170
本文介绍了获取警告"从不同规模和QUOT的整数转换为指针;从以下code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在code是:

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

下面是 C code按下收益 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;

什么是特定警告的原因是什么?

What is the reason for the particular warning?

推荐答案

您可以使用使用intptr_t 来确保整数具有相同的宽度为指针。这样,你不需要去发现你的特定平台的东西,它会在另一个平台上工作太(不像无符号长解决方案)。

You can use intptr_t to ensure the integer has the same width as pointer. This way, you don't need to discover stuff about your specific platform, and it will work on another platform too (unlike the unsigned long solution).

#include <stdint.h>

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

从C99标准措施:

Taken from the C99 Standard:

7.18.1.4可容纳对象指针整数类型

7.18.1.4 Integer types capable of holding object pointers

1的
  以下类型指定一个签名
  整数类型的属性,
  任何有效的指针无效可
  转换为这种类型,然后转换
  回指向void,而
  结果将比较等于
  原来指针:

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

intptr_t

这篇关于获取警告&QUOT;从不同规模和QUOT的整数转换为指针;从以下code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆