这里我的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
}
}
感谢, 安迪
你编译了什么架构?如果64位,NSInteger将是64位,但int将是32位。 –
你的问题只是关于显然错误的调试器输出?或者你的代码不能按预期工作? –
[Objective C integer comparison error]可能的重复(http://stackoverflow.com/questions/16725029/objective-c-integer-comparison-error) –