Movement against float.init being nan
Paul Backus
snarwin at gmail.com
Tue Aug 23 23:35:28 UTC 2022
On Tuesday, 23 August 2022 at 21:53:35 UTC, Ali Çehreli wrote:
> On 8/23/22 14:40, Dave P. wrote:
>
> >> And yes, 0 happens to be a valid garbage value.
> >
> > The default value for a struct imported via importC is all
> bits 0.
>
> Steve said the same thing but I don't see it on the ImportC
> page (yet?):
>
> https://dlang.org/spec/importc.html
>
> I wonder why D would do that.
Global and static variables in C are initialized to all-zero
bits, regardless of type. Here's the relevant paragraph from the
C11 standard:
> If an object that has automatic storage duration is not
> initialized explicitly, its value is indeterminate. If an
> object that has static or thread storage duration is not
> initialized explicitly, then:
>
> if it has pointer type, it is initialized to a null pointer;
> if it has arithmetic type, it is initialized to (positive
> or unsigned) zero;
> if it is an aggregate, every member is initialized
> (recursively) according to these rules, and any padding is
> initialized to zero bits;
> if it is a union, the first named member is initialized
> (recursively) according to these rules, and any padding is
> initialized to zero bits;
Source: http://port70.net/~nsz/c/c11/n1570.html#6.7.9p10
Presumably this behavior was implemented in an attempt to conform
to this part of the C standard.
More information about the Digitalmars-d
mailing list