Sunday, 15 August 2010

c++ - Why is an extra comma not allowed in a parameter list when it is allowed in a brace initialization? -


After one of my old questions ()

Is there any technical reason why parameter list function announcements and In the function call, code like brace initialization has not been adapted to generation?

What do I mean:

It's OK, additional , is ignored:

  int Generated_array [] = {1, 2, 3,};  

For continuity, will not it even be able to allow?

  int someFunc (int v1, int v2, int v3,) {. ..} int ret_val = someFunc (1, 2, 3,);  

I can not see how this will make the compilation even more complex, but I'm probably not thinking anything. I think that in fact it would be a little simpler.

Of course it can argue that this brace is not useful in the form of initialization, but there should be cases where the code generation was allowed at least a little bit simpler.

Justification for the back of a comma is justified to make big machine-generation easier. In this way, if you need to write a program that generates the initial list of the array, you can type something like this:

  printf ("int arr [] = {" ); For (int i = 0; i  

If the following commas were not allowed, then you have to ensure that it has not been generated; And honestly, while doing this is not hard to do, it's just ugly and pain in the neck.

There is no practical requirement for the machine, although large function parameter lists are generated, and these lists look good without any good tracing of commas, hence the function parameter and the same thing in the call There is no need to give it.


No comments:

Post a Comment