Proposal : allocations made easier with non nullable types.
Michel Fortin
michel.fortin at michelf.com
Mon Feb 9 03:58:36 PST 2009
On 2009-02-09 06:41:59 -0500, Ary Borenszweig <ary at esperanto.org.ar> said:
> How would you do this?
>
> X x;
>
> if(someCondition) {
> x = new SomeX();
> } else {
> x = new SomeOtherX();
> }
Well, the declaration could be transformed to this:
X x = new X;
But since x is not used before being reassigned (for all code paths),
the compiler could just leave it uninitialized until you do the
assignement yourself. But then perhaps the "new X" should not be elided
unless the constructor and and destructor are pure.
Another question is what happens when X is an abstract class.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list