2012-07-31 102 views
-2

的情况下离奇结果我使用__int64数据类型在64位AIX和我正在比较的情况下,奇异结果与064位整数中的比较

代码段:

__int64 indexExistingPart = GetValue(); // GetValue always returns -1. 

if (indexExistingPart < 0) 
{ 
    DoSomething(); //control never comes to this part of the code 
} 

我也尝试将0赋值给另一个__int64变量并用于比较。但是,这也不起作用:

__int64 indexExistingPart = GetValue(); // GetValue always returns -1. 

__int64 temp =0; 

if (indexExistingPart < temp) 
{ 
    DoSomething(); //control never comes to this part of the code 
} 

为什么比较运算符不适用于64位整数?有什么解决方法吗?

+5

'__int64'不是标准的类型 - 它是如何定义,其中和?另外,GetValue()的返回类型是什么? – 2012-07-31 10:00:23

+2

你确定__int64没有签名吗? – 2012-07-31 10:03:30

+0

@Paul:GetValue()的返回类型很长。当我在AIX上使用__int64时,我没有收到任何编译错误。 – user1565291 2012-07-31 11:33:46

回答

0

症状符合__int64是您项目中的unsigned long的typedef。 (__int64不是由AIX提供的类型,至少根据IBM文档)尝试这个代替:

#include <stdint.h> // or #include <sys/types.h>, or #include <inttypes.h> 

int64_t indexExistingPart = GetValue(); // or "signed long indexExistingPart ..." 

if (indexExistingPart < 0) 
{ 
    DoSomething(); 
}