Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why initializer list cannot be main's parameter? how to propose it?

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:

  • What could be the disadvantages or problems derived of allowing an initializer list as the main only parameter? (i couldn't think of any).
  • Which would be the correct way to propose to the standards committee this addition (or any other change)?
like image 638
PaperBirdMaster Avatar asked Sep 30 '13 16:09

PaperBirdMaster


1 Answers

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.

like image 165
jxh Avatar answered Nov 15 '22 05:11

jxh