Following up on an old question of mine (Is there any relevance to an extra "," in the end of a brace initialization?)
Are there any technical reasons why the parameter list in function declarations and function calls has not been made code-generation-friendly like the brace initialization?
What I mean is:
This is ok, the extra ,
is ignored:
int generated_array[] = {
1,
2,
3,
};
For consistency, wouldn't it also make sense to allow this?
int someFunc(
int v1,
int v2,
int v3,
){...}
int ret_val = someFunc(
1,
2,
3,
);
I cannot see how it would make compilation more complicated, but perhaps there is something I'm not thinking of. I would guess it would actually simplify it slightly.
Of course one can argue that it's not as useful as the brace initialization, but there should be cases where code generation would be made at least a tiny bit simpler if this was allowed.
As JSON is based on a very restricted subset of JavaScript syntax, trailing commas are not allowed in JSON.
A trailing comma, also known as a dangling or terminal comma, is a comma symbol that is typed after the last item of a list of elements. Since the introduction of the JavaScript language, trailing commas have been legal in array literals. Later, object literals joined arrays.
We can find the rationale for allowing the trailing comma in an initializer-list in the Rationale for International Standard—Programming Languages—C which says:
K&R allows a trailing comma in an initializer at the end of an initializer-list. The Standard has retained this syntax, since it provides flexibility in adding or deleting members from an initializer list, and simplifies machine generation of such lists.
This rationale does not apply to the other cases.
This discussion on comp.lang.c++.moderated
: Are comma-separated lists ending in a comma legal? also cites the same rationale.
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