可能的重复项: 对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()调用?
发布评论