Movement against float.init being nan
jmh530
john.michael.hall at gmail.com
Tue Aug 23 18:30:04 UTC 2022
On Tuesday, 23 August 2022 at 11:08:36 UTC, Zoadian wrote:
> On Tuesday, 23 August 2022 at 00:50:21 UTC, Walter Bright wrote:
>> C and C++ initialize them to garbage unless it is a
>> global/static variable. That's probably the worst option, as
>> it results in Heisenbugs that are very hard to track down.
>
> I agree that NaN for uninitialized floats is the best option.
> However, can we get a switch to force initialization of floats?
> it would be of great help to quickly find the place where one
> forgot to initialize a variable.
Walter makes good points in favor of NaN as a default, but I
agree this would be useful for identifying the source of the
problem, so long as it is primarily used for debugging purposes.
For instance, if we could do something like
`debug(force-float-initialization, VALUE)` where VALUE defaults
to zero but represents the value that uninitialized floats would
get initialized to, then that would be helpful (a pragma might be
an alternative to a debug statement). After all, if you are
writing a function that unexpectedly returns a NaN, then you can
put that up top and see if it returns something else. Being able
to modify the VALUE would help identify the issue in more
complicated functions.
More information about the Digitalmars-d
mailing list