float init 0 request
GB
gb542 at gmail.com
Sun Aug 23 00:53:31 UTC 2026
On Saturday, 22 August 2026 at 19:44:51 UTC, Walter Bright 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.
f = 3.14; // compiler now knows -> explicitlyAssigned has
transitioned from false to true
writeln(f); // OK
An an explicit initializer used in @UNASSIGNED declaration should
not be allowed:
@UNASSIGNED float f = 0; // ERROR: @UNASSIGNED variable f
cannot have an initializer; it must be explicitly assigned after
declaration.
More interestingly, if @UNASSIGNED has type independence, it
could work with all declarations that have default initialization:
@UNASSIGNED float f; // memory contains default float
@UNASSIGNED int i; // memory contains 0
@UNASSIGNED MyStruct s; // memory contains default struct
More information about the Digitalmars-d
mailing list