Not initialized out argument error

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 17 14:29:27 PDT 2014


On 6/17/2014 2:55 AM, bearophile wrote:
> I have not used SAL so I can't tell. It has nonnull compile-time
> tests, and tests of copy or write of the _whole_ span of an
> array, that look nice and are missing in D.

I have no idea what that would be 'nice' for, except some optimizations. Nor do 
I think that, in general, such an attribute is mechanically checkable. If it is 
not checkable, it may wind up being the source of obscure bugs.


>> I suspect that is a guess.
> I've written a ton of D1/D2 code, and functions like foo are very
> uncommon in my code. I can do a statistic on my code.

That would be your personal coding style (and there's nothing wrong with that), 
but it is not evidence for correctness.


> But I think when you use an out argument you are asking for
> a meaningful return value. Not initializing a variable because
> you need a zero is common, but you usually don't call a function
> with an out argument because you want a init value. So I think
> the two cases are sufficiently different.

The assumption that a .init value is not meaningful is completely arbitrary.


> I think Tobias Pankrath is saying that accepting code like this:

You are correct that they are logically the same. But I don't believe that at 
all implies that they are equivalent in error-proneness.



More information about the Digitalmars-d mailing list