Can now use alias for collapsing multiple fields in nested structs

Basile B. b2.temp at gmx.com
Sat Jan 4 20:30:01 UTC 2025


On Saturday, 4 January 2025 at 20:01:33 UTC, Nick Treleaven wrote:
> On Thursday, 2 January 2025 at 21:14:25 UTC, ryuukk_ wrote:
>> On Thursday, 2 January 2025 at 19:08:06 UTC, Walter Bright 
>> wrote:
>>> [...]
>>
>> that's hard to learn, why is it possible to do `outter.b = 42`?
>
> That's how it works in C11. The spec shows some useful use 
> cases:
>
> https://dlang.org/spec/struct.html#anonymous
>
>> ```
>> struct outer {
>>     int a;
>>     struct {
>>         int b;
>>         int c;
>>     } inner;
>>     int d;
>> }
>> ```
>>
>> now it is easier to learn, it is an anonymous struct called 
>> `inner`
>
> That complicates the parser, beginners would forget to type the 
> `;` after a struct definition and get confused at the parse 
> errors.
>
> Why do you need an anonymous struct type there? Naming it and 
> using the struct name for `inner` isn't difficult, and it 
> doesn't seem needed that often.

anonymous structs are only useful in unions. dot end of the 
story. Or eventually that can help to have better header. You're 
just silly quys.


More information about the Digitalmars-d mailing list