On Sunday, 6 October 2024 at 05:41:10 UTC, ryuukk_ wrote:
There is no new syntax to invent

instead of writing this error:
```
onlineapp.d(8): Error: no identifier for declarator `stats`
```

you generate a random identifier and assign it

```D
extern(D) static Identifier generateAnonymousId(const(char)[] name)
```

https://github.com/dlang/dmd/blob/master/compiler/src/dmd/identifier.d#L165

I'm very far from being bright, but i know simple logic

The problem is not the ability to generate an id, the problem is that the declaration is over. Anything after the closing brace is a *new declaration*.

Whitespace is not significant in D, so you have to invent a new syntax to to mean the declaration continues.

D sees this:

```d
struct {
  int x;
  int y;
} something;
```

as this:

```d
struct {
  int x;
  int y;
}
// DECLARATION OF ANONYMOUS STRUCT OVER.

something; // this is something different, unrelated to the struct above.
```

One declaration defines an anonymous struct, and one that is a new declaration `something;`. Or if you are in a function, `something;` is treated as a statement.

You can't change existing syntax, as that would break code, so you need new syntax.

C allows this because structs are *required* to end with a semicolon. So the compiler knows the thing after the brace is part of the same declaration.

-Steve
  • 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 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
    • Re: Why is ... Sergey via Digitalmars-d-learn
      • Re: Why... ryuukk_ via Digitalmars-d-learn
        • Re:... Sergey via Digitalmars-d-learn

Reply via email to