0
#include <stdio.h>
#include <AssertMacros.h>

int main( int argc, char* argv[] )
{
    int error = 1;

    verify_noerr( error );
    require_noerr( error, Oops );  //<---- Is Oops a callback method?

    printf("You shouldn't be here!\n");

Oops: ;                    // <--v____  Is this a method declaration?
    return error;          // <--^        Why the ':' followed by the ';'?
}

此代码来自 2006 年的 iOS 文档。我意识到在 C 中,没有声明返回类型的方法的默认返回类型是 int。但这真的是一种依靠这个原则的方法吗?为什么是冒号分号?我最后的想法是它是一个 C 块,但Wikipedia 另有说法

我难住了。

4

2 回答 2

2

这个:

Oops: ;

是一个标签,它可以是 a 的目标goto

我猜这require_noerr是一个宏,如果是错误代码,它会扩展到goto给定标签。error

当发生错误时,您将使用此系统退出函数。它允许清理标签和函数末尾之间的代码(简单的if (error) return;不允许)。

于 2013-04-27T22:02:28.690 回答
1

这在 C 编程中称为标签。

在 c 代码中,您可以使用 goto 跳转到该标签

goto Oops;
于 2013-04-27T22:02:17.310 回答