9

代码是:

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

这是 C code push回报 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;

特定警告的原因是什么?

4

4 回答 4

21

您可以使用intptr_t来确保整数与指针具有相同的宽度。这样,您无需发现有关您的特定平台的内容,它也可以在另一个平台上运行(与unsigned long解决方案不同)。

#include <stdint.h>

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

取自 C99 标准:

7.18.1.4 能够保存对象指针的整数类型

1 以下类型指定有符号整数类型,其属性是任何指向 void 的有效指针都可以转换为该类型,然后再转换回指向 void 的指针,结果将与原始指针进行比较:

intptr_t

于 2011-04-18T13:06:32.563 回答
0

What are you trying to do? Pointers are not integers, and you are trying to make a pointer out of 0 or 1, depending on the situation. That is illegal.


If you were trying to pass a pointer to a ABC containing 0 or 1, use this:

ABC tmp = GetCar(i) == term_Null()? 0 : 1;
Push(size, &tmp);
于 2011-04-18T10:26:11.110 回答
0

您正在尝试将整数值(0 或 1)强制转换为 void 指针。

此表达式始终是值为 0 或 1 的 int:(GetCar(i) == term_Null()? 0 : 1)

然后您尝试将其转换为 void 指针(POINTER)( typedef void * POINTER)。

这是非法的。

于 2011-04-18T10:27:47.107 回答
0

由于这个问题使用与您的 32 位到 64 位移植问题相同的 typedef,我假设您使用的是 64 位指针。正如 MByd 所写,您将 int 转换为指针,并且由于 int 不是 64 位,您会收到该特定警告。

于 2011-04-18T10:31:16.420 回答