为什么在C ++中不允许递归main()调用? [英] Why are recursive main() calls not allowed in C++?

查看:251
本文介绍了为什么在C ++中不允许递归main()调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能的重复项:

对main()函数的限制

在C ++中递归到main()中是否合法?




b $ b

我在 C ++入门中读到 main 不允许被递归调用,在这里的一些相关问题确实证实这是非法的。

I read in C++ Primer that main is not allowed to be called recursively, and in some related questions here on SO it is indeed confirmed that it is illegal.

但为什么是非法的?只要避免堆栈溢出,在它自身内调用 main 有什么问题?

But why is it illegal? As long as you avoid a stack overflow, what's the problem with calling main within itself?

推荐答案

好吧,标准状态:

3.6.1.3
函数main不能在程序中使用

3.6.1.3 "The function main shall not be used within a program."

5.2.2.9
允许递归调用,除了名为main的函数

5.2.2.9 "Recursive calls are permitted, except to the function named main"

是beause main()是一个特殊函数,用作程序的入口点。我会说保持它特别,不要把它下来的正常功能的水平,因为它不是。

I guess it is beause main() is a special function used as the entry point to the program. I'd say keep it special, don't take it down the level of a normal function, because it is not.

这篇关于为什么在C ++中不允许递归main()调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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