Replies: 2 comments 1 reply
-
|
I think it is normal for anonymous substructure members to be initialized with designators without braces. Regarding mixing of initializers with designators and without them, C allows that and there is no ambiguity. Why do you insist on disallowing it? Here is a interesting use case: |
Beta Was this translation helpful? Give feedback.
-
|
The example is an array-designated init expr, those are different beasts again. Mixing those will 'normal' initializations would be ok. But mixing field designators (which can be out of order (why!?) with normal ones makes no sense . 'Just because it's possible' is not a good reason to allow something. Switching 2 field-designators would change next non-field init. Also it just doesn't make sense. And keeping things consistent is a nice thing. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm currently fixing an issue in the struct-init analyser, and run into something that is actually weird: anonymous sub-structs are initialized with braces during normal inits, but without in field-designated inits:
type Foo struct {
i32 a;
struct {
char b;
}
i16 c;
}
Foo[] ff = {
{ 1, { 2 }, 3 }, // normal init, {} needed for b
{ .a = 1, .b = 2, .c = 3 }, // field-designated init, no braces needed for b
}
C2 does not allow mixing field-designated inits with other inits (which is good). So for anonymous sub-structs
we have no way to designate them. Forbidden anonymous members is an options, but some people probably 'cant live
without' it. Nasty.
Beta Was this translation helpful? Give feedback.
All reactions