gpt4 book ai didi

ios - "Oops: ; return error;"是 C 中的有效方法声明吗?

转载 作者:太空宇宙 更新时间:2023-11-04 07:28:16 24 4
gpt4 key购买 nike

#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 ';'?
}

此代码来自iOS documentation from 2006 .我意识到在 C 中,没有声明返回类型的方法的默认返回类型是 int。但这真的是一种依靠该原理的方法吗?为什么冒号分号?我最后的想法是它是一个 C block ,但是 Wikipedia says otherwise .

我很难过。

最佳答案

这个:

Oops: ;

是一个标签,可以是goto的目标。

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

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

关于ios - "Oops: ; return error;"是 C 中的有效方法声明吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16257289/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com