本文介绍了函数中有多个返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C中处理多个返回的优秀编程风格是什么?

函数返回不同的值?

- 要设置为返回的变量值,是在返回的函数的

结尾?

- 要有多个不同值的返回值?


哪个更喜欢,还有更好的方法吗?


/ nergal

What is a good programming style in C to handle multiple returns in a
function that returns different values?
- To have a variable that is set to the return value, which is in the
end of the function returned?
- To have multiple returns with different values?

Which to prefer, and is there a better way?

/nergal

推荐答案



可能是一种风格,但由于没有任何清理

mec在C中的hanism,我更喜欢C函数只返回一次。


它更容易调试(只有一个地方设置断点),节省了狩猎次数

多次返回,如果函数必须在返回之前释放任何锁或其他资源,生活会更轻松。


-

Ian Collins。

Probably a point of style, but due to the absence of any clean up
mechanism in C, I prefer a C function to have a single return.

It''s easier to debug (only one place to set a breakpoint), saves hunting
for multiple returns and makes life much easier if the function has to
release any locks or other resources before it returns.

--
Ian Collins.




意见各不相同。我赞成单一的退货声明,而且我并不孤单。

。为什么?因为我认为它使代码更容易理解。但

很多人都希望尽快回来。为什么?因为他们认为它使代码更容易理解!


这不是正确性问题,而是风格问题。所以 - 你选择。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999


电子邮件:rjh在上述域名, - www。

Opinions vary. I favour a single return statement, and I''m not alone in
that. Why? Because I think it makes the code easier to understand. But
many people prefer to return as soon as possible. Why? Because they
think it makes the code easier to understand!

This is not a matter of correctness, but of style. So - you choose.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.




计划对你来说很容易。对于时间优化,您可以在函数中选择

多个返回语句。


-N

Program which seems easy to you. For time optimization, you can choose
multiple return statements in the function.

-N


这篇关于函数中有多个返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:12
查看更多