Not initialized out argument error

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 17 03:27:43 PDT 2014


On Tue, 17 Jun 2014 02:24:43 -0700
Walter Bright via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> On 6/17/2014 1:55 AM, bearophile wrote:
> > Walter Bright:
> >
> I see it as annoying and nothing to do with 'strictness'. D default
> initializes all variables that don't have an explicit initializer.
> This is normal for D, and is a nice convenience. There's no reason
> that 'out' should behave differently.

I would hope that the compiler could and would optimize out setting the out
parameter to its init value when it's unnecessary - e.g. if the parameter is a
built-in type, or it's a struct without an opAssign (so that skipping setting
it to the init value won't change the semanticts), and the compiler can
determine that it's guaranteed to be assigned to, then the compiler would skip
setting the out parameter to its init value. After all, why pay for setting
the out parameter on function entry when it's not necessary? But I would
expect that to be an optimization, and the compiler obviously wouldn't always
be able to make it. The same would ideally go for normal variables which are
default-initialized, but it wouldn't surprise me if not having much code flow
analysis in the compiler would make it so that such optimizations couldn't
happen very often.

- Jonathan M Davis


More information about the Digitalmars-d mailing list