main()调用main() [英] main() called inside main()

查看:94
本文介绍了main()调用main()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




int main(无效)

{

main();

返回0;

}


wat该标准是否就上面的代码片段说了什么?

解决方案

没什么,

这将导致无限循环。吃了大量的处理器时间,并且

你可能会看到你的PC挂起。


谢谢。

< br>

ra*********@gmail.com 写道:< blockquote class =post_quotes> int main(void)
{
main();
返回0;
}

wat做标准说关于上面的代码片段?




这是对main的递归调用,这是完全合法的。


像任何无限递归调用,它将超过某个系统资源限制,或者它将无限期地运行(如果编译器优化了

尾递归)。

return 0;永远不会到达。


-

Keith Thompson(The_Other_Keith) ks ***@mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。


Prasad写道:

没什么,


错了,标准说如果你递归地调用main会发生什么。

这将导致无限循环。吃了大量的处理器时间,并且你可能会看到你的PC挂起。


或者编译器可能无法优化它,在这种情况下循环将不会是无限的,因为你将耗尽堆栈空间。或者进程限制

可能会阻止它记录CPU时间。或者编译器可能

将它优化为某种形式的睡眠永远指令。

谢谢。




请提供回复时的上下文,Google不是* Usenet。请参阅 http:// clc-wiki上的

Google部分.net / wiki / Intro_to_clc
以及它们链接到的网站。

-

Flash Gordon,生活在有趣的时代。

网站 - http://home.flash -gordon.me.uk/

comp.lang.c发布指南和介绍:
http://clc-wiki.net/wiki/Intro_to_clc

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php


hi,

int main(void)
{
main();
return 0;
}

wat does the standard says about the above code snippet?

解决方案

Nothing,
This will result in infinite loop. Eating a lot of processor time, and
you may see your PC hang.

Thanks.


ra*********@gmail.com writes:

int main(void)
{
main();
return 0;
}

wat does the standard says about the above code snippet?



It''s a recursive call to main, which is perfectly legal.

Like any infinite recursive call, it will either exceed some system
resource limit, or it will run indefinitely (if the compiler optimizes
tail recursion).

The "return 0;" will never be reached.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


Prasad wrote:

Nothing,
Wrong, the standard says what will happen if you call main recursively.
This will result in infinite loop. Eating a lot of processor time, and
you may see your PC hang.
Or the compiler could fail to optimise it in which case the loop will
not be infinite since you will run out of stack space. Or process limits
might prevent it from eating a log of CPU time. Or the compiler might
optimise it to some form of sleep forever instruction.
Thanks.



Please provide context when replying, Google is *not* Usenet. See the
Google section at http://clc-wiki.net/wiki/Intro_to_clc and the sites it
links to.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php


这篇关于main()调用main()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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