在没有return语句的情况下到达函数结尾 [英] Reaching end of function without return statement

查看:242
本文介绍了在没有return语句的情况下到达函数结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ANSI X3.159-1989,第3.6.6.4节,第33-35行指出:

ANSI X3.159-1989, section 3.6.6.4, lines 33-35 state:

如果执行了不带表达式的return语句,并且 函数调用的值由调用方使用,其行为是 不明确的.到达终止函数的}等价于 执行不带表达式的return语句."

"If a return statement without an expression is executed, and the value of the function call is used by the caller, the behavior is undefined. Reaching the } that terminates a function is equivalent to executing a return statement without an expression."

我一直在通过ISO/IEC 9899:1999(E)ISO/IEC 9899:2011(E)ISO/IEC 14882:2011(E)ISO/IEC 14882:2014(E)查找类似的语句,尤其是第二句话,但是我发现的所有内容都与main函数有关.如果有人可以将我指向这些文件中任何一个的正确位置(我不在乎哪个),我将不胜感激.

I've been looking through ISO/IEC 9899:1999(E), ISO/IEC 9899:2011(E), ISO/IEC 14882:2011(E), and ISO/IEC 14882:2014(E) for similar statements, especially the 2nd sentence, but about all I've found pertains to function main. If someone could point me to the correct spot(s) in any one of these documents (I don't care which) I'd appreciate it.

推荐答案

关于第一句话(您的信息来源似乎有误或过时):

As to the first sentence (your source appears to be wrong or outdated):

C 2011 6.8.6.4返回语句

1 带有表达式的return语句不得出现在其返回类型为void的函数中.没有表达式的return语句只能出现在返回类型为void的函数中.

C 2011 6.8.6.4 The return statement

1 A return statement with an expression shall not appear in a function whose return type is void. A return statement without an expression shall only appear in a function whose return type is void.

第二句:

C 2011 6.9.1函数定义

12 如果到达了终止函数的},并且调用者使用了函数调用的值,则行为是不确定的.

C 2011 6.9.1 Function definitions

12 If the } that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined.

这篇关于在没有return语句的情况下到达函数结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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