Why does my C++ compiler allow recursive calls to main? [duplicate]

*爱你&永不变心* 提交于 2019-12-01 18:51:48

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 within a program.


The shall construct

A diagnosable rule is defined as (§1.4.1):

The set of diagnosable rules consists of all syntactic and semantic rules in this International Standard except for those rules containing an explicit notation that “no diagnostic is required” or which are described as resulting in “undefined behavior.”

§3.6.1.3 defines a diagnosable rule.

According to §1.4.2:

— If a program contains no violations of the rules in this International Standard, a conforming implementation shall, within its resource limits, accept and correctly execute that program.

— If a program contains a violation of any diagnosable rule, a conforming implementation shall issue at least one diagnostic message, except that

— If a program contains a violation of a rule for which no diagnostic is required, this International Standard places no requirement on implementations with respect to that program.


Conclusion

A compiler is free to do whatever it wants to do. Try the same code on Comeau Online (a more conforming compiler). I get this error "function "main" may not be called or have its address taken"

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!