Movement against float.init being nan

Steven Schveighoffer schveiguy at gmail.com
Wed Aug 24 14:03:08 UTC 2022


On 8/24/22 1:14 AM, Walter Bright wrote:
> On 8/23/2022 5:00 PM, Steven Schveighoffer wrote:
>> On one hand, it's a C struct. But on the other hand, it's a D 
>> function. Who's rules are used?
> 
> The C rules. This is because D is importing C code, so it better behave 
> like C code. C code does initialize floats and doubles to 0.0 if they 
> are placed in static data. It is not reasonable that D would leave 
> imported C structures uninitialized when C does, and so initializing 
> them to 0.0 is a reasonable choice.
> 

So to paraphrase this, D does initialize local C structure values, but 
initializes doubles/floats to 0 to be consistent with C static 
initialization. In other words, it *doesn't* use the C rules of not 
initializing locals that have no explicit initialization. But it *does* 
use the C rules of what value to initialize with.

I actually proved this too with a test, so that's good news! Maybe I 
just need to define all my structs using C :P

-Steve


More information about the Digitalmars-d mailing list