括号周围的返回值 [英] Parenthesis surrounding return values

查看:128
本文介绍了括号周围的返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

常常在ANSI C code,我可以看到括号sorrounding一个返回值。

Quite often in ANSI C code I can see parenthesis sorrounding a single return value.

像这样: -

int foo(int x) {
  if (x)
    return (-1);
  else
    return (0);
}

为什么要使用()围绕在这些情况下返回值?有任何想法吗?我看不出有什么理由。

Why use () around the return value in those cases? Any ideas? I can see no reason for that.

推荐答案

有真的不是一个原因......它只是旧约定。

There really isn't a reason...it's just old convention.

为了节省空间,程序员经常会做最后的数学在返回行,而不是它自己的线路和括号确保大多是在那里更容易地看到,它是返回,这样一条语句:

To save space, programmers would often do the final math in the return line instead of on it's own line and the parens ensure are mostly there to make it easier to see that it is a single statement that is returned, like this:

return (x+i*2);

而不是

int y = x+i*2;
return y;

括号变成了习惯,把它卡住了。

The parenthesis became a habit and it stuck.

这篇关于括号周围的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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