Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The last draft of C++14 that I was able to find says, regarding main() [3.6.1]:

An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int, but otherwise its type is implementation-defined. All implementations shall allow both

— a function of () returning int and

— a function of (int, pointer to pointer to char) returning int

and (paragraph 5)

If control reaches the end of main without encountering a return statement, the effect is that of executing

return 0;

Does this mean that all of the following are legal C++14 minimal programs? If any isn't, why not?

  1. auto main() -> int {}
  2. auto main() { return 0; }
  3. auto main() {}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
193 views
Welcome To Ask or Share your Answers For Others

1 Answer

  1. Is legal, the second and the latter aren't because of the following reasons:

  2. The return type of the main function cannot be deduced since CWG 1669 was accepted and the standard will be reworded as:

    An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a declared return type of type int, but otherwise its type is implementation-defined.

    This got its way into n4140. More on this: http://wg21.cmeerw.net/cwg/issue1669

  3. The same as above


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...