float init 0 request
GB
gb542 at gmail.com
Sun Aug 23 11:17:30 UTC 2026
On Sunday, 23 August 2026 at 10:09:28 UTC, Nick Treleaven wrote:
> On Sunday, 23 August 2026 at 00:53:31 UTC, GB wrote:
>> D already has:
>> - storage exists
>> - default value exists
>>
>> If the compiler had access to more information:
>> compiler knowledge -> explicitlyAssigned = false
>> compiler knowledge -> explicitlyAssigned = true
>>
>> Then the following would be possible:
>>
>> @UNASSIGNED float f; // compiler knows -> explicitlyAssigned =
>> false
>> writeln(f); // ERROR: @UNASSIGNED f has not been is
>> explicitly assigned.
>
> https://dlang.org/changelog/2.113.0.html#dmd.fastdfa.uninitialized
>
> It depends on if the compiler can prove that `f` is still
> uninitialized, which it can't always.
If only all problems were this easy to solve.
@mustAssign float f;
Note, it doesn't need to prove that f is uninitialized. It needs
to prove that f is definitely assigned. If it can't prove that,
reject the use.
conservatism is acceptable -> inability to prove assignment
produces an error.
Problem solved!
The harder part of this idea is how to establish precise rules
for control flow, function calls, ref/out, and aggregates; those
edge cases are where the idea will either become workable or fall
apart.
More information about the Digitalmars-d
mailing list