It crashes on execution:
#include <iostream>
int main ()
{
if(main());
return 0;
}
Why?
It crashes due to Stackoverflow of course, since, there is no terminating condition,
but technically the C++
Compiler is allowed not to compile it, since in C++:
main() cannot be called from within a program.
The address of main() cannot be taken.
The main() function cannot be overloaded.
What the standard says:
Annex to C Compatibilty
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
ISO/IEC 14882:2003(E) 3.6.1 (3)
The function main shall not be used (3.2) within a program. The linkage (3.5) of main is implementation-defined. A program that declares main to be inline or static is ill-formed. The name main is not otherwise reserved. [Example: member functions, classes, and enumerations can be called main, as can entities in other namespaces. ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With