2

我认为我做的一切都是正确的,但是 NSLog 输出与悬停在变量上显示的正确值不匹配。合成和点符号工作正常。
将鼠标悬停在所有变量上会显示正确的值,如 // 注释中所示。但是 NSlog 在 Debugger 控制台中显示不正确;输出也显示在 // 注释中。

在测试中,屏幕类的一个实例:

{   int i;
    char j;
}

在 AppDelegate 中:

test.i = 10;    // hover shows 10        OK
test.j = 'z';   // hover shows 122 'z'   OK
NSLog(@"i= %i, j= %c"),test.i, test.j;// hover shows 10,122 'z'OK  
but Debugger Console shows  i= 2097168, j= $  


int k = 10; // hover shows 10        OK
char l = 'z';   // hover shows 122 'z'   OK
NSLog(@"k= %i, l= %c"),k, l;          // hover shows 10,122 'z'OK  
but Debugger Console shows  k= 6055, l= ,

我错过了什么?或者这是 Xcode 3.2.4、OSX 10.6 中的真正错误?

4

1 回答 1

5

You've closed the parentheses for NSlog() before passing the format arguments. Change this:

NSLog(@"i= %i, j= %c"),test.i, test.j;

to this:

NSLog(@"i= %i, j= %c",test.i, test.j);

Aside from separating arguments in function calls, commas can also be used to separate statements. Your attempt is equivalent to:

NSLog(@"i= %i, j= %c"); // An NSLog with no args, will print garbage.
test.i; // A valid, though pointless, statement.
test.j; // A valid, though pointless, statement.
于 2012-11-27T05:34:55.157 回答