Partially initialized structs?

Arredondo arm.plus at gmail.com
Wed Feb 26 23:47:41 UTC 2025


On Wednesday, 26 February 2025 at 10:19:17 UTC, Hipreme wrote:
>
>     ```d
>     struct S
>     {
>         int[100] a;
>         int b = 0;
>         static S defaultInit(int b)
>         {
>            S s = void;
>            s.b = b;
>            return s;
>         }
>     }
>     ```

Thank you for this Hipreme. I do have a question though, wouldn't 
this create two copies of S? one at construction and then another 
at the call site after defaultInit returns?

Regarding safety, I'm well aware I'm playing with fire here. For 
now I'm just experimenting to see if something like this is even 
worth it performance-wise.

Cheers!
Arredondo.


More information about the Digitalmars-d-learn mailing list