Using static properties and methods of variable in its own initializer
Dejan Lekic
dejan.lekic at gmail.com
Thu Apr 10 08:26:57 UTC 2025
On Wednesday, 9 April 2025 at 19:47:43 UTC, Dave P. wrote:
> In my opinion, it should be fine to refer to static properties
> or methods and so
> ```d
> void main(){
> size_t y = y.sizeof;
> }
> ```
> should work, but because of how this was implemented it does
> slightly change the semantics if you happen to shadow a global.
>
> Should this be fixed? or is this the intended design of the
> language?
Is this not good enough for you?
```d
void main(){
size_t y = size_t.sizeof;
}
```
In short, types few properties too, .sizeof being one of them.
Other properties are .alignof and .init . More about it:
https://dlang.org/spec/property.html#type
More information about the Digitalmars-d
mailing list