从返回int的函数返回任何内容(MS VC ++ 6.0) [英] Returning nothing from a function that returns an int (MS VC++ 6.0)

查看:99
本文介绍了从返回int的函数返回任何内容(MS VC ++ 6.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MS Visual C ++ 6.0编译器如何处理以下内容?!


int main()

{

...

}


我的意思是没有返回0;。根本没有返回int。这怎么编译?!我是C#专家,而且从不编译C#。请根据编译器假设的内容及其实际内容来解释您的答案...


提前致谢。

解决方案

< blockquote>编译器将发出错误,因为函数在其定义指示它应该返回值时。



编译器将发出错误,因为函数在其定义指示应该返回值时不返回值。



在C中你绝对正确但是C ++允许main可选地返回一个int值。

当它没有返回时任何隐含的''返回0''都是假定的。


亲切的问候,


Jos


不在Microsoft的土地上,int main(){}在C中编译没有错误,并在C ++中发出警告。


当然我绝对同意你的陈述乔斯,这是愚蠢的我希望微软能够证明符合标准的一切。


How does the MS Visual C++ 6.0 compiler deal with the following?!

int main()
{
...
}

I mean that there''s no "return 0;". There''s no int returned at all. How does this compile?! I''m a C# expert, and this never compiles on C#. Please explain your answer in terms of what the compiler assumes and what it does actually...

Thanks in advance.

解决方案

The compiler will issue an error because the function does not return a value when its definition indicates that it should.


The compiler will issue an error because the function does not return a value when its definition indicates that it should.

In C you''re absolutely right but C++ allows main to optionally return an int value.
When it doesn''t return anything an implicit ''return 0'' is assumed.

kind regards,

Jos


Not in Microsoft land, there int main(){} compiles without error in C and gives a warning in C++.

Of course I absolutely agree with your statement Jos, it was foolish of me to expect Microsoft would be able to demonstrate anything like conformance to a standard.


这篇关于从返回int的函数返回任何内容(MS VC ++ 6.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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