[Issue 2642] .init contains zeroes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 21 01:30:22 PST 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2642





------- Comment #6 from 2korden at gmail.com  2009-02-21 03:30 -------
One of the solutions is to introduce non-nullable types (both reference and
value-types). In this case T.init would be useless (and thus may be safely
removed from language*), because user will *have to* initialize it:

double d; // compare to "double? d;" which is ok to be non-initialized
double dd = 100.0;

Same for structs:

Foo f; // not initialized (CT-error or write-only until initialized)
Foo ff = Foo(); // ok, default-initialized

Note that this is very close to classes (same rule - same syntax):

Bar b; // not initialized (CT-error or write-only until initialized)
Bar bb = new Bar(); // ok, default-initialized

As a general rule for all types,

T t; // is not an initialized value, a compile-time error is raised,
// or just not allowed to be read until initialized (relaxed rule)
T t = initializer_expression; // ok, an initialized value

--
* I don't mind if T.init will be removed from language specs altogether as I
never found it useful. It may still be left for some time in compiler internals
(to copy T[] prior to calling T.__ctor), just don't expose it to users.


-- 



More information about the Digitalmars-d-bugs mailing list