我目前正在致力于从 32 位移植到 64 位。我收到警告:
cast to pointer from integer of different size
在下面的代码中
AcLogFileWrite(
(FILE *) pOut->pTrace->logFileHandle, /* warning in this line */
outRecord,
outRecordLen);
AcLogFileWrite()
的原型(prototype)是
int AcLogFileWrite(
FILE * handle,
char * data,
int bytes);
此处参数pOut->pTrace->logFileHandle
的类型为int
。
如何解决此警告?
最佳答案
不能在 32 位 int 中存储 64 位。如果logFileHandle
必须存储一个指针,唯一可以安全地做到这一点的整数类型是 uintptr_t
或intptr_t
来自<stdint.h>
。或者您可以typedef void*
。由于无论如何您都要移植到新的 ABI,因此二进制兼容性不是问题,现在是修复它的好时机。
如果你绝对不能改变 int
类型的定义,那么你必须在ILP64
下编译模型,其中int
, long
和void*
都是 64 位宽。
关于c++ - 从不同大小的整数获取到指针的警告转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32494062/