为什么在C ++中不允许递归main()调用?

编程入门 行业动态 更新时间:2024-10-11 23:24:38
本文介绍了为什么在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()调用?

本文发布于:2023-11-09 04:14:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571375.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   中不   main

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!