2

This question about the meaning of a trailing comma was posted today. I closed it as duplicate of this one.

Another poster re-opened it , asserting that since the term "exact duplicate" is an oxymoron and I had admitted it was not an "exact duplicate" then it should be open.

However I (and another poster) feel the issue the question is asking about is superbly answered by the suggested duplicate which provides a lot of additional rationale (unlike the bare-bones answer which the warrior has approved after re-opening).

I don't think we should have 3 separate questions for each of these pieces of code:

int a = { 1, };
int a[1] = { 1, };
struct S s = { 1, };

As a comparable example, there are dozens of questions asking variations on "what does i = i++; do?" which all get closed as a duplicate of this one despite the questions have different variables names, and different expressions.

1
  • 2
    Seems borderline to me. You could certainly argue that a question about the syntax for initializing a scalar is different from one about initializing an array. Commented Dec 1, 2014 at 1:41

1 Answer 1

1

Sorry, I'm kinda bad with this website, but I'm going to give a shot at defending one of the posters on there. The C++11 standard says in [dcl.init] p13 that

The form of initialization (using parentheses or =) is generally insignificant, but does matter when the initializer or the entity being initialized has a class type; see below. If the entity being initialized does not have class type, the expression-list in a parenthesized initializer shall be a single expression.

Yet would you argue that all questions about initialization should be closed as duplicates of each other? I see lots of questions on the website about different forms of initialization, where even though the syntax is very similar, the questions and answers are very different.

I also don't agree with your example:

int a = { 1, };
int a[1] = { 1, };
struct S s = { 1, };

The last one only has similar semantics because there's only one element in the initializer, but change it up and it becomes a very different scenario. I would argue the same thing for my question. A scalar initializer has different semantics than initializing an array even though the same rules apply.

2
  • This is just about whether or not brace-enclosed initializers can have a trailing comma. And you could say about any scenario, "change it up a bit and it becomes a very different scenario".
    – M.M
    Commented Dec 1, 2014 at 2:53
  • Note that expression-list in your quote refers to the part of the list excluding the trailing comma (see [syntax]/2)
    – M.M
    Commented Dec 1, 2014 at 2:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .