获取警告"从不同规模和QUOT的整数转换为指针;从以下code [英] Getting the warning "cast to pointer from integer of different size" from the following 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屋!