I'm getting NAN out of nowhere
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 9 10:54:49 PDT 2015
On 7/9/15 1:04 PM, bachmeier wrote:
> On Thursday, 9 July 2015 at 15:18:18 UTC, Adam D. Ruppe wrote:
>> On Thursday, 9 July 2015 at 15:14:43 UTC, Binarydepth wrote:
>>> float prom;
>>
>> You didn't initialize this variable. Set it to 0.0 and it will work.
>>
>> Like how pointers are initialized to null automatically in D, floats
>> are auto initalized to NaN in D. The idea is to make use of an
>> uninitialized variable obvious quickly so you are encouraged to
>> initialize it.
>
> Is there a reason the compiler doesn't identify this as an error?
> prom+=nums[nem]; doesn't make sense if prom hasn't been initialized.
prom has been initialized, to NaN by the compiler. It's not an accident.
All data is default initialized in D unless specifically initialized to
void.
-Steve
More information about the Digitalmars-d-learn
mailing list