`static` on module-level functions
Steven Schveighoffer
schveiguy at gmail.com
Fri Jul 7 13:31:59 UTC 2023
On 7/7/23 6:38 AM, IchorDev wrote:
>
> Well yes, I even mentioned that in the OP. It's just that I'd expect
> using `static` "incorrectly" to cause an error, like `const` does.
> Instead, marking something as `static` *actually* does nothing, and
> nothing really tells you, so it causes a bit of a placebo effect.
D allows no-op attributes in many cases because you can possibly apply
attributes to a group via `attribute:` or `attribute { ... }`, and you
may not want to fine-tune which things can get the attribute to avoid
errors.
Here's a fun one:
```d
enum foo() {
return "what?";
}
```
What does this mean? `enum` is a storage class, and any storage class
applied to a function is going to cause the function to be inferred
return type. So effectively, the `enum` does nothing but take the place
of `auto`. (`foo` is a function that returns `string`)
However, I can't think of a valid reason to allow `static` on a
module-level scope. Applying static to a declaration at module-level
should be a no-op. So maybe that's one "use" of static that can be
eliminated.
-Steve
More information about the Digitalmars-d-learn
mailing list