什么(实际)情况,当与警告&QUOT一个功能;控制到达非void函数&QUOT结束;叫做? [英] What (actually) happens, when a function with the warning "control reaches end of non-void function" is called?

查看:280
本文介绍了什么(实际)情况,当与警告&QUOT一个功能;控制到达非void函数&QUOT结束;叫做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这消息意味着,我只是想知道为什么它的不可以错误信息,但只是一个警告?

I know what this message means, I just wondered why it is not an error message, but just a warning?

在这种情况下,会发生什么?例如,假设我有一个函数

What happens in this case? For example, suppose I have a function

int f()
{
}

,当我把它时会发生什么?结果
该编译器增加了在这种情况下返回的未初始化 INT ?结果
或丢失的回报可能会导致堆栈损坏?结果
或者它的(绝对)的未定义行为的?

<子>用gcc 4.1.2和4.4.3测试

编辑:阅读我明白了一件事的答案,阅读评论 - 另一个..

Reading the answers I understand one thing, reading the comments - another..

好吧,让我们总结一下:它的未定义行为的。那么,这意味着,它的可能的导致堆栈损坏,对不对? (它甚至意味着,我的电脑可能开始通过麦克风插孔扔在我烂西红柿,尖叫 - 你做了什么?)。

OK, let's summarize: it's undefined behavior. Then, this means, that it is possible to result in stack corruption, right? (it even means, that my computer may start throwing rotten tomatoes over me through the mic jack, screaming - "what have you done???").

但如果是这样,那么为什么在这里上回答说,这堆腐败是不可能发生的,并在同一时间,该行为是未定义的?

But if so, then why the top answer here says, that stack corruption can't happen and, in the same time, that the behaviour is undefined?

和不确定的方面?来电者,试图用没有返回值,或功能刚刚结束是不确定的,如果它必须返回值,但是它不?

And undefined in respect to? The caller, that tries to use the "not returned value", or just the end of the function is undefined, if it must return value, but it doesn't?

或者它不是不确定的行为,并不仅仅是用户,谁尝试使用的值(即不退还,科特迪瓦哦!)将接收未定义的的?换句话说 - 只是一些垃圾的价值,仅此而已可能发生

Or it's not undefined behavior, and just the user, who tries to use the value (that is not returned, d'oh!) will "receive" undefined value? In other words - just some garbage value and nothing more can happen?

推荐答案

答:没有,缺少的回报将不会导致堆栈损坏

A: No, the missing return would not cause stack corruption

答:是的,该行为将是未定义如果主叫方试图读取和/或使用(!未定义)返回值

A: Yes, the behavior would be "undefined" if the caller tried to read and/or use the (undefined!) return value.

PS:

下面是C ++引文:

C ++ 03§6.6.3/ 2:

C++03 §6.6.3/2:

流动关闭的函数的末尾相当于没有返回
  值;这会导致不确定的行为在一个返回值
  功能。

Flowing off the end of a function is equivalent to a return with no value; this results in undefined behavior in a value-returning function.

这篇关于什么(实际)情况,当与警告&QUOT一个功能;控制到达非void函数&QUOT结束;叫做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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