我在一些示例代码中遇到过这个:
- (IBAction) startPlayLowNote:(id)sender {
UInt32 noteNum = kLowNote;
UInt32 onVelocity = 127;
UInt32 noteCommand = kMIDIMessage_NoteOn << 4 | 0;
OSStatus result = noErr;
require_noerr (result = MusicDeviceMIDIEvent (self.samplerUnit, noteCommand, noteNum, onVelocity, 0), logTheError);
logTheError:
if (result != noErr) NSLog (@"Unable to start playing the low note. Error code: %d '%.4s'\n", (int) result, (const char *)&result);
}
“logTheError:”是做什么的?这个语法叫什么?我在哪里可以找到有关它的更多信息?
最佳答案
logtheError:
是一个标签。 require_noerr
宏中有一个 goto
,它会在出现错误时跳转到指定的标签。这是一个简化和扩展的 goto/label 示例,没有任何有趣的业务或宏:
int call2Functions(void)
{
int err = function();
if (err)
goto errorExit;
err = function2();
errorExit:
return err;
}
它最初是 C 语法。您可以在 C 标准的6.8.1 标记语句部分了解更多信息。
关于objective-c - 这个 Objective-C(或者 c)语法有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8619034/