我应该如何处理“从”void *“转换为”int“失去精度”当在64位机器上编译32位代码? [英] How should I handle "cast from ‘void*’ to ‘int’ loses precision" when compiling 32-bit code on 64-bit machine?
问题描述
我有一个包在32位机器上编译和工作正常。我现在试图让它在64位机器上编译,并发现以下错误 -
I have a package that compiles and works fine on a 32-bit machine. I am now trying to get it to compile on a 64-bit machine and find the following error-
error: cast from ‘void*’ to ‘int’ loses precision
有没有编译器标志来抑制这些错误?
Is there a compiler flag to suppress these errors? or do I have to manually edit these files to avoid these casts?
推荐答案
问题是,在32bits中, int (一个32位整数)将保存一个指针值。
The issue is that, in 32bits, an int (which is a 32bit integer) will hold a pointer value.
当移动到64位时, - 它不够大,不能容纳64位指针。 intptr_t 类型是为此而设计的。
When you move to 64bit, you can no longer store a pointer in an int - it isn't large enough to hold a 64bit pointer. The intptr_t type is designed for this.
这篇关于我应该如何处理“从”void *“转换为”int“失去精度”当在64位机器上编译32位代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!