On Saturday, 5 October 2024 at 16:40:46 UTC, Salih Dincer wrote:
On Saturday, 5 October 2024 at 06:35:57 UTC, ryuukk_ wrote:

No, i don't want to do:


```C
struct EntityDef
{
    struct Stats
    {
        int hp;
    } stats;
}
```

Repeating the same name 3 times, i should go back to the stone age too no?

C and all other C like languages allow me to be concise

Why is it a D thing to be backward?

In the coding scheme, fields/members/methods may be at the beginning, middle, or end of the structure, or may not be identifiers to the right of the anonymous structs. In structures, a lot (I wish it was in bitfield) has been taken from C. Especially not using typedef and not having extra semicolons make D stand out even with these. As for anonymous structures, they have to be like this in order to be used with unions.

I think everything is as it should be, and even more: Please include the relevant comment line (the // characters next to the anonymous struct) in the code and be amazed by the change :)

```d
struct Foo
{
    int bar;

    //struct {/*
    Baz baz;
    struct Baz
    {
        auto opAssign(int value)
          => baz = value;//*/
        int baz;
    }
}

void main()
{
    Foo foo;
    foo.bar = 7;
    foo.baz = 42;
    
    imported!"std.stdio".writeln(foo); /*
    with opAssign()      Anonymous
    Foo(7, Baz(42))  or  Foo(7, 42)    */
}
```

Thank you to the creators and maintainers of the D.

SDB@79


I literally don't understand what your code does

I'm not sure this is related to my suggestion
  • Re: Why is this ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
    • Re: Why is ... ryuukk_ via Digitalmars-d-learn
      • Re: Why... Sergey via Digitalmars-d-learn
        • Re:... ryuukk_ via Digitalmars-d-learn
    • Re: Why is ... Salih Dincer via Digitalmars-d-learn
      • Re: Why... ryuukk_ via Digitalmars-d-learn
      • Re: Why... ryuukk_ via Digitalmars-d-learn
    • Re: Why is ... Steven Schveighoffer via Digitalmars-d-learn
      • Re: Why... ryuukk_ via Digitalmars-d-learn
        • Re:... Steven Schveighoffer via Digitalmars-d-learn
          • ... ryuukk_ via Digitalmars-d-learn
            • ... Steven Schveighoffer via Digitalmars-d-learn
      • Re: Why... Nick Treleaven via Digitalmars-d-learn
        • Re:... ryuukk_ via Digitalmars-d-learn
          • ... Nick Treleaven via Digitalmars-d-learn
            • ... ryuukk_ via Digitalmars-d-learn
              • ... Salih Dincer via Digitalmars-d-learn

Reply via email to