float init 0 request
claptrap
clap at trap.com
Sat Aug 15 09:57:38 UTC 2026
On Friday, 14 August 2026 at 08:09:45 UTC, Jonathan M Davis wrote:
> On Friday, August 14, 2026 1:05:06 AM Mountain Daylight Time
> Alexandru Ermicioi via Digitalmars-d wrote:
>> On Friday, 14 August 2026 at 06:38:02 UTC, Walter Bright wrote:
>> > Floats are default initialized to NaN so people will be
>> > coerced to explicitly code what they want the initialized
>> > value to be.
>> >
>> > I've seen enough code where the programmer forgot to
>> > initialize a float, it was defaulted to 0, and the wrong
>> > result was not
>>
>> Why not make it an error, a float that is not explicitly
>> initialized? Would be way better than implicit nan
>> initialization, right?
>
> The language relies on the ability to default-initialize
> objects. For instance, that's what happens when you allocate a
> dynamic array or increase its length.
Make it an error where it can be detected, for fields and locals.
And make it NaN for expanding arrays.
That would be more useful than the current situation.
More information about the Digitalmars-d
mailing list