简体   繁体   English

GNU g ++编译器下main()的返回类型

[英]Return type of main( ) under GNU g++ Compiler

As per ISO_14882_2014 根据ISO_14882_2014

3.6 Start and termination [basic.start] 3.6开始和终止[basic.start]

3.6.1 Main function [basic.start.main] 3.6.1主要功能[basic.start.main]

2 An implementation shall not predefine the main function. 2实现不得预定义主要功能。 This function shall not be overloaded. 此功能不得重载。 It shall have a declared return type of type int, but otherwise its type is implementation-defined. 它必须具有声明的int类型的返回类型,否则它的类型是实现定义的。

but otherwise its type is implementation-defined. 但是否则它的类型是实现定义的。 That means compiler may have its own return type for main() . 这意味着编译器可能对main()有自己的返回类型。 Can you point me to the location where GNU G++ compiler says about main() 's return type. 您能指出我GNU G ++编译器所说的main()返回类型的位置吗?

The return type must be int ; 返回类型必须为int the "its type" that follows refers to main , not to the return type. 后面的“其类型”是指main ,而不是返回类型。 That is, the arguments that main takes are implementation defined. 也就是说, main接受的参数是实现定义的。 Each implementation must, however, provide at least int main() and int main(int, char**) . 但是,每个实现都必须至少提供int main()int main(int, char**)

Assuming i386 architecture. 假设i386体系结构。 From glibc start.S we call __libc_start_main . glibc start.S开始,我们称为__libc_start_main From glibc csu/libc-start.c __libc_start_main we call main with the pointer type int (*main) (int, char **, char **) (the MAIN_AUXVEC_DECL shouldn't be defined on i386 I think, only for powerpc). glibc csu / libc-start.c __libc_start_main中,我们用指针类型int (*main) (int, char **, char **)调用main int (*main) (int, char **, char **)我认为不应在i386上定义MAIN_AUXVEC_DECL ,仅适用于powerpc) 。 So the implementation defined type of main function is int main(int, char **, char **) . 因此, main函数的实现定义类型为int main(int, char **, char **) Because of how stack works on i386, the forms int main(void) and int main() and int main(int) and int main(int, char**) will work. 由于堆栈在i386上的工作方式,因此int main(void)int main()以及int main(int)int main(int, char**)都可以使用。 The main return type is int . main返回类型是int

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM