Can now use alias for collapsing multiple fields in nested structs
Derek Fawcus
dfawcus+dlang at employees.org
Mon Dec 30 17:09:11 UTC 2024
On Monday, 30 December 2024 at 12:08:53 UTC, ryuukk_ wrote:
> On Sunday, 29 December 2024 at 04:10:13 UTC, Walter Bright
> wrote:
>> On 12/28/2024 5:23 PM, Derek Fawcus wrote:
>>> It was... That particular preprocessor game largely became
>>> unnecessary once we gained C11 anonymous structs and unions.
>>
>> D had anonymous structs and unions long before C11.
>>
>
> but D can't do that
Yeah - the C usage, is something like this:
```C
#ifdef C89_STYLE
struct Outer {
int o_x;
struct {
int i_a;
int i_b;
} s;
};
#define o_a s.i_a
#define o_b s.i_b
#else /* C89_STYLE */
struct Outer { /* C11 Style */
int o_x;
struct {
int o_a;
int o_b;
};
};
#endif /* C89_STYLE */
struct Outer os;
void foo(void) {
os.o_x = 1; os.o_a = 2; os.o_b = 3;
}
```
Whereas this new D enhancement seems to be somewhat different, as
in D it seems the structs always need to have tags.
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.
More information about the Digitalmars-d
mailing list