does c++ standard prohibit the void main() prototype?

前端 未结 6 1804
隐瞒了意图╮
隐瞒了意图╮ 2020-12-11 18:27

In section 3.6.1.2 of both C++ Standard 1998 and 2003 editions,

An implementation shall not predefine the main function. This function shall not be ov

6条回答
  •  长情又很酷
    2020-12-11 18:48

    The standard is saying that the return type must be int, but that the rest of the type is up to the implementation. For example, you could make a standard-compliant (but not terribly useful) C++ compiler that used.

    int main(int secondsSinceSystemStart, int myFavoriteNumber, char* aFunnyJoke)
    

    From Wikipedia:

    In C and C++, the function prototype of the main function looks like one of the following:

    int main(void)
    int main(int argc, char **argv)
    

    The parameters argc, argument count, and argv, argument vector, respectively give the number and value of the program's command-line arguments. The names of argc and argv may be any valid identifier, but it is common convention to use these names. Other platform-dependent formats are also allowed by the C and C++ standards; for example, Unix (though not POSIX.1) and Microsoft Visual C++ have a third argument giving the program's environment, otherwise accessible through getenv in stdlib.h:

    int main(int argc, char **argv, char **envp)
    

    Mac OS X and Darwin have a fourth parameter containing arbitrary OS-supplied information, such as the path to the executing binary:

    int main(int argc, char **argv, char **envp, char **apple)
    

提交回复
热议问题