int
workmad3 wrote: | ||
---|---|---|
The valid C++ main signatures are:
|
cppStandard wrote: |
---|
3.6.1 Main function .... 2 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 of the following definitions of main: int main() { /* ... */ } and int main(int argc, char* argv[]) { /* ... */ } |
void main
and then use a different mechanism for specifying the return value of the function (which is still int). So if you are up to the challenge, go ahead and do it but you better have a good reason for reinventing c++ so that main can return types other than int.
int
because the standard says it must be int
.int main() { /* stuff */ }
int main(int argc, char* argv[]) { /* stuff */ }
,int main(/* some other args */) { /* stuff */ }
int
(because the standard says so).int main(int argc, char* argv[], char* envp[]) { /* stuff */ }
void main()
is not allowed in proper C++ code, period.int x[10];
|
|
A freestanding implementation is one in which execution may take place without the benefit of an operating system, and has an implementation-defined set of libraries that includes certain language-support libraries - IS |
GCC aims towards being usable as a conforming freestanding implementation, or as the compiler for a conforming hosted implementation. By default, it will act as the compiler for a hosted implementation ... To make it act as a conforming freestanding implementation for a freestanding environment, use the option -ffreestanding; ... To build an OS kernel, you may well still need to make your own arrangements for linking and startup. http://gcc.gnu.org/onlinedocs/gcc/Standards.html |
|
|
g++-4.8 -std=c++11 -O2 -Wall -pedantic-errors -ffreestanding main.cpp -c && echo ok ok |
g++-4.8 -std=c++11 -O2 -Wall -pedantic-errors main.cpp && echo ok main.cpp:2:79: error: '::main' must return 'int' double main( int array1[], double array2[], int array_size1, int array_size_2 ) ^ main.cpp:2:8: error: first argument of 'int main(int*, double*, int, int)' should be 'int' [-Wmain] double main( int array1[], double array2[], int array_size1, int array_size_2 ) ^ main.cpp:2:8: error: second argument of 'int main(int*, double*, int, int)' should be 'char **' [-Wmain] main.cpp:2:8: error: third argument of 'int main(int*, double*, int, int)' should probably be 'char **' [-Wmain] main.cpp:2:8: error: 'int main(int*, double*, int, int)' takes only zero or two arguments [-Wmain] |