2013-07-22 38 views
3

这里我的C知识可能有一个漏洞,但我对这种情况发生的原因有些困惑。令人困惑的LLDB输出

(lldb) p lineGroup 
(NSInteger) $17 = -1 
(lldb) p (lineGroup > 4) 
(bool) $18 = true 
(lldb) p (lineGroup < 0) 
(bool) $19 = false 
(lldb) p (-1 < 0) 
(bool) $20 = true 
(lldb) p ((int)lineGroup < 0) 
(bool) $21 = false 
(lldb) p ((int)lineGroup > 4) 
(bool) $22 = true 
(lldb) 

lineGroup变量分配如下:

- (void)gotLineGroupInformation:(NSString *)lineGroupString 
{ 
    NSInteger lineGroup = [lineGroupString integerValue]; 
    if(lineGroup >= 0) 
    { 
     // Always gets called 
    } 
    else 
    { 
     // Never gets called 
    } 
} 

感谢, 安迪

+0

你编译了什么架构?如果64位,NSInteger将是64位,但int将是32位。 –

+1

你的问题只是关于显然错误的调试器输出?或者你的代码不能按预期工作? –

+0

[Objective C integer comparison error]可能的重复(http://stackoverflow.com/questions/16725029/objective-c-integer-comparison-error) –

回答

2

的LLDB问题似乎是完全一样的,如Objective C integer comparison error

卡尔Norum时说:在他的回复中:

确认 - 这是lldb IR解释器中的一个错误。

下面是补丁的链接,修复它:http://lists.cs.uiuc.edu/pipermail/lldb-commits/Week-of-Mon-20130520/008569.html


关于你的代码,我试图重现bug没有更迭与这个测试:

NSString *lineGroupString = @"-1"; 
NSInteger lineGroup = [lineGroupString integerValue]; 
if(lineGroup >= 0) 
{ 
    NSLog(@"positive"); 
} 
else 
{ 
    NSLog(@"negative"); // This log is correctly called every time 
} 

也许你应该尝试使用NSLog进行调试(特别是输入函数后,lineGroupString的值是什么?)。

+0

是的,这是“Objective C整数比较错误”。 Xcode 4.6.x中的lldb-179存在安迪在此处报告的错误;它被固定在树lldb svn源头的顶部。任何通过Xcode 4.6.x发布的Xcode都会包含修复程序。 –