在 C/Objective-C 中将返回值放在括号中的意图是什么? [英] What is the intention of putting return values in parentheses in C/Objective-C?

查看:49
本文介绍了在 C/Objective-C 中将返回值放在括号中的意图是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些将方法/函数的返回值括在括号中的代码.

有什么作用?

我看到的代码拍摄了一张图片,调整了它的大小,然后返回了它.

- (UIImage *)resizeImage:(UIImage *)image{////这里有一些有趣但无关紧要的调整大小的代码//返回(图像);}

解决方案

至少就 C 而言,它没有区别.括号不是必需的,但它们不会改变 return 语句的含义.return语句的语法是

<前>返回声明:return 表达式opt ;

并且表达式非终结符的产生式之一是括号表达式,或( 表达式 ).

I've come across some code that surrounds the return value from a method/function in parentheses.

What does that do?

The code I saw took an image, resized it and then returned it.

- (UIImage *)resizeImage:(UIImage *)image
{
    //
    // some fascinating, but irrelevant, resizing code here
    //

    return (image);
}

解决方案

At least as far as C is concerned, it makes no difference. The parens aren't necessary, but they don't change the meaning of the return statement. The grammar of the return statement is

return-statement:
    return expressionopt ;

and one of the productions of the expression non-terminal is a parenthesized-expression, or ( expression ).

这篇关于在 C/Objective-C 中将返回值放在括号中的意图是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆