bail:
if ( err && image ) {
CGImageRelease( image );
image = NULL;
}
if ( provider ) CGDataProviderRelease( provider );
if ( colorspace ) CGColorSpaceRelease( colorspace );
*imageOut = image;
return err;
上述代码的 bail: 部分是什么意思,咋没见过这种代码风格?
代码源自ios example SquareCam(http://developer.apple.com/library/ios/#samplecode/SquareCam/Introduction/Intro.html)
这是goto
语句跳转的标签。
你正在看的代码:SquareCamViewController.m
。使用了一个宏命名require
,像这样:
require( error == nil, bail );
这个宏是在AssertMacros.h
头文件中定义。他将标签作为第二参数,如果第一参数的值为false使用goto
。
在C中,使用goto和标签来跳转清除函数结尾的代码是最常用的方法。
bail:
是一个标签,这是标准的C语法。在普通的代码中很少用。最常用的方法是和goto
一起用,但是请最好不要用goto
这个语法。
你给的链接中的代码是用在require
函数中,如果require
失败,代码就会将中间的代码都跳过,直接跳回到bail
标签。