union default initialization values

Adam D Ruppe destructionator at gmail.com
Tue Dec 5 19:28:17 UTC 2023


On Tuesday, 5 December 2023 at 19:24:51 UTC, confuzzled wrote:
> Given the following union
>
> union F
> {
>     double x;
>     struct {
>         ulong lo;
>         ulong hi;
>     }
> }

The default value of this would be `double.init`, since the first 
member of the union is a `double`, which is a kind of NaN. This 
is non-zero.

You can use `double x = 0;` to specify you want it to be zero 
initialized.

>     fp.x.writefln!"%20.98f"; // Also, why is precision 
> completely lost after 16 digits (18 if I change the type of x 
> to real)?

idk about this.


More information about the Digitalmars-d-learn mailing list