我尝试移植到 64 位的 C 源代码在 32 位环境中运行时没有任何警告。当我在64位Linux环境下使用编译gcc(Ubuntu 4.4.1-4ubuntu9)4.4.1进行编译时,主要显示以下警告:
warning: cast to pointer from integer of different size
以上警告最多。我使用了 uintptr_t 类型,大部分警告都被删除了。我可以使用 uintptr_t 将 int/unsigned int 类型更改为 64 位有利的类型。但如何更改以下类型以兼容 64 位:
typedef void* POINTER;
我更改了以下代码:
typedef unsigned int ABC;
进入
typedef uintptr_t ABC
我收到以下警告:
warning: passing argument 2 of ‘function’ from incompatible pointer type
note: expected ‘ABC *’ but argument is of type ‘unsigned int *’
此外,将类型 def 更改为 uintptr_t (之前的 int 或 unsigned int)后,我遇到了大多数警告,如下所示:
warning: inlining failed in call to ‘abc_StringCopy’: call is unlikely and code size would grow
tptp_StringCopy函数如下:
static __inline__ char* abc_StringCopy(void)
{
char *copy;
copy = (char*)Malloc(yyleng+1);
strcpy(copy, yytext);
return copy;
如何消除这些警告?
最佳答案
unsigned int
在 64 位系统上不能与 uintptr_t
互换。 int
和 unsigned int
在 64 位机器上仍然是 32 位值,但 uintptr_t
变成了 64 位类型。该类型之所以称为 uintptr_t 是因为该类型是与指针宽度相同的无符号整数值。这意味着 uintptr_t
在 32 位计算机上为 32 位宽,但在 64 位计算机上变为 64 位宽。
在您的代码中,这意味着,通过您的 typedef
更改,在 64 位计算机上 NAT*
是指向 64 位变量的 64 位指针,但 unsigned int*
是一个指向 32 位变量的 64 位指针。
clause_ComputeSplitFieldAddress
仍然需要 unsigned int*
参数。
关于c - 将 32 位 C 源代码移植到 64 位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2393978/