Can now use alias for collapsing multiple fields in nested structs
Walter Bright
newshound2 at digitalmars.com
Thu Jan 2 08:25:41 UTC 2025
On 12/30/2024 9:09 AM, Derek Fawcus wrote:
> Whereas this new D enhancement seems to be somewhat different, as in D it seems
> the structs always need to have tags.
Not exactly.
Anonymous structs in D are used to simplify layout, as in:
```
struct S
{
int a;
union
{
struct { int j, k; }
double d;
}
}
...
S.a
S.j
S.k
S.d
```
No extra tags needed.
and:
```
struct S
{
struct { int a, b; }
}
...
S.a
S.b
```
The anonymous struct there is pointless.
> Not that I'm arguing against such an enhancement; simply that the C limitation,
> and preprocesser games being used as a partial justification is long obsolete.
The C11 thing is just copying what D did.
More information about the Digitalmars-d
mailing list