Using static properties and methods of variable in its own initializer
Atila Neves
atila.neves at gmail.com
Mon Apr 14 13:36:51 UTC 2025
On Thursday, 10 April 2025 at 14:35:49 UTC, Dave P. wrote:
> On Thursday, 10 April 2025 at 08:26:57 UTC, Dejan Lekic wrote:
>> On Wednesday, 9 April 2025 at 19:47:43 UTC, Dave P. wrote:
>>> [...]
>>
>> 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
>
> This is just a trivial example. In general, repeating the type
> twice is error prone.
Yes, which is why I would recommend:
```
const y = size_t.sizeof;
```
More information about the Digitalmars-d
mailing list