C
krümelkacker schrieb:
Ich nehme an, deine Antwort soll mir sagen, dass die Beispiele nur mit der "richtigen" Zahl von Klammerungen funktioniert und dass diese Zahl unbekannt ist.
Genau.
krümelkacker schrieb:
Das überrascht mich jetzt, weil ich dachte, brace elision würde hier genauso funktionieren.
Leider (oder zum Glück - ich nehme an, man hat sich etwas dabei gedacht) nicht.
n3337 8.5.1 schrieb:
11 In a declaration of the form
T x = { a };
braces can be elided in an initializer-list as follows.105 If the initializer-list begins with a left brace,
then the succeeding comma-separated list of initializer-clauses initializes the members of a subaggregate;
it is erroneous for there to be more initializer-clauses than members. If, however, the initializer-list for a
subaggregate does not begin with a left brace, then only enough initializer-clauses from the list are taken
to initialize the members of the subaggregate; any remaining initializer-clauses are left to initialize the next
member of the aggregate of which the current subaggregate is a member. [ Example:
float y[4][3] = {
{ 1, 3, 5 },
{ 2, 4, 6 },
{ 3, 5, 7 },
};
is a completely-braced initialization: 1, 3, and 5 initialize the first row of the array y[0], namely y[0][0],
y[0][1], and y[0][2]. Likewise the next two lines initialize y[1] and y[2]. The initializer ends early and
therefore y[3]s elements are initialized as if explicitly initialized with an expression of the form float(),
that is, are initialized with 0.0. In the following example, braces in the initializer-list are elided; however
the initializer-list has the same effect as the completely-braced initializer-list of the above example,
float y[4][3] = {
1, 3, 5, 2, 4, 6, 3, 5, 7
};
The initializer for y begins with a left brace, but the one for y[0] does not, therefore three elements from
the list are used. Likewise the next three are taken successively for y[1] and y[2]. —end example ]
...
105) Braces cannot be elided in other uses of list-initialization.
array wurde ja in den Entwurf des Standards aufgenommen lange bevor die Regeln für die List-Initialisierung fertig waren. Ich vermute also, das Problem wurde einfach übersehen.