Why does my C++ compiler allow recursive calls to main? [duplicate]
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Is it legal to recurse into main() in C++? #include <iostream> using namespace std; int main() { static int var = 5; std::cout << --var; if(var) main(); } gcc compiles the code http://ideone.com/lIp3A . I know that main cannot be used inside main in C++. How come this code compiles? 回答1: The code is ill-formed because it violates the shall construct of §3.6.1.3 §3.6.1.3 says : The function main shall not be used