Discussion Thread: DIP 1035-- at system Variables--Community Review Round 2

Paul Backus snarwin at gmail.com
Fri Feb 26 13:42:18 UTC 2021


On Friday, 26 February 2021 at 09:57:03 UTC, Walter Bright wrote:
> > Example: Short String
>
> This example boils down to an invariant not being maintained if 
> the struct is void-initialized.

Note that it's not just void initialization. Overlap in a union 
and reinterpreting casts can also create instances with broken 
invariants; e.g.,

union U
{
     int n;
     ShortString s;
}

@safe
void main()
{
     U u = { n: 0xDEADBEEF };
     writeln(u.s[]); // undefined behavior
}


More information about the Digitalmars-d mailing list