它在执行时崩溃:
#include <iostream>
int main ()
{
if(main());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么?
Sad*_*que 11
它当然会因Stackoverflow而崩溃,因为没有终止条件,但从技术上讲,C++
编译器不允许编译它,因为在C++中:
main() cannot be called from within a program.
The address of main() cannot be taken.
The main() function cannot be overloaded.
Run Code Online (Sandbox Code Playgroud)
标准说的是:
C兼容性的附件
3.6
Change: Main cannot be called recursively and cannot have its address taken
Rationale: The main function may require special actions.
Effect on original feature: Deletion of semantically well-defined feature
Difficulty of converting: Trivial: create an intermediary function such as mymain(argc, argv).
How widely used: Seldom
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
254 次 |
最近记录: |