Allow designated initialization of struct

Salih Dincer salihdb at hotmail.com
Sun Nov 3 23:35:24 UTC 2024


On Friday, 1 November 2024 at 12:26:25 UTC, ryuukk_ wrote:
> 
> ```C
> enum State
> {
>     IDLE,
>     RUN,
>     ATTACK,
> }
>
>
> fn void main()
> {
>     State state = IDLE;
>     if (state == RUN) {
>         // run
>     }
> }
> ```
>
> D needs to to better

You want that magic in C and more. But D is a much more stable 
language

```C
#include <assert.h>

typedef enum {
   One, Two, Three, Four
} Numbers;

typedef struct {
     size_t counter;
} S;


int main()
{
   assert(Four == 3);
   auto arr[] = { One, Two, Three, Four };

   int Four = 43;
   S myStruct = {
     counter : Four
   };
   assert(myStruct.counter == 43);
}
```

SDB at 79



More information about the dip.ideas mailing list