The valid C++ main
signatures are the following:
int main()
int main(int argc, char *argv[])
int main(int argc, char **argv)
But isn't allowed to declare main
taking an initializer list:
int main(std::initializer_list<char *> args)
AFAIK the initializer list could be implemented as a pair of pointers or a pointer (this could be the argv
parameter) plus a length (this could be deduced from the argc
parameter), and its storage could be automatic, temporary, or static read-only memory depending on the situation.
So i think that an std::initializer_list<char *>
could handle and manage without any problem the command line parameters, then i'm wondering why this hypothetical main
signature wasn't added after the approval of the initializer lists on the C++11 standard, and because of that i'm asking:
main
only parameter? (i couldn't think of any).Although there are two ways of specifying main()
in a program, most (all?) current implementations of the C++ run-time call the main()
function the same way (they pass the arguments as (int, char *[])
irrespective to how main()
is declared). Your proposal would require the C++ run-time of all implementations to figure out which kind of main()
the program is using, and call the right main()
. If you really want this functionality for yourself, you can always provide an implementation of main(int, char *[])
that converts the arguments into an initializer list like object (such as vector<>
), and then calls a new entry point function of your choice.
The process for submitting a proposal is described at the Standard C++ website. The basic steps are: (1) float the idea on their Usenet group/mailing list; (2) draft a proposal, solicit feedback, and update the proposal accordingly; and (3) repeat the process until the proposal is accepted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With