收到警告“从不同大小的整数转换为指针”从下面的代码
代码是:
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;
特定警告的原因是什么?
The code is:
Push(size, (POINTER)(GetCar(i) == term_Null()? 0 : 1));
Here is the C code push
returns ABC
which is
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
intptr_t
来确保整数与指针具有相同的宽度。这样,您不需要发现有关您的特定平台的信息,并且它也可以在另一个平台上工作(与unsigned long
解决方案不同)。摘自 C99 标准:
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 theunsigned long
solution).Taken from the C99 Standard:
您正在尝试将整数值(0 或 1)转换为 void 指针。
此表达式始终是值为 0 或 1 的 int:
(GetCar(i) == term_Null()? 0 : 1)
并且您尝试将其强制转换为 void 指针 <代码>(POINTER) (
typedef void * POINTER
)。这是非法的。
You are trying to cast an integer value (0 or 1) to a void pointer.
This expression is always an int with value 0 or 1:
(GetCar(i) == term_Null()? 0 : 1)
And you try casting it to void pointer
(POINTER)
(typedef void * POINTER
).Which is illegal.
由于这个问题使用与 32 位到 64 位移植问题相同的 typedef,我假设您使用的是 64 位指针。正如 MByd 所写,您正在将 int 转换为指针,并且由于 int 不是 64 位,因此您会收到该特定警告。
Since this question uses the same typedefs as your 32bit to 64bit porting question I assume that you're using 64 bit pointers. As MByd wrote you're casting an int to a pointer and since int isn't 64 bit you get that particular warning.
你想做什么? 指针不是整数,并且您尝试根据情况从
0
或1
中创建指针。那是非法的。如果您尝试将指针传递给包含
0
或1
的ABC
,请使用以下命令:What are you trying to do? Pointers are not integers, and you are trying to make a pointer out of
0
or1
, depending on the situation. That is illegal.If you were trying to pass a pointer to a
ABC
containing0
or1
, use this: