void init of out variables

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Sat Aug 19 16:05:26 PDT 2017


On 8/18/2017 11:24 PM, Nicholas Wilson wrote:
> On Saturday, 19 August 2017 at 06:23:10 UTC, Igor Shirkalin wrote:
>> On Saturday, 19 August 2017 at 06:20:28 UTC, Nicholas Wilson wrote:
>>> I have a function that takes a large matrix as an out parameter.
>>> Is there a way to do `=void` for an out parameter like there is for is for a 
>>> plain declaration?
>>> enum M = 2600;
>>> void f() {
>>>     float[M] mean = void; // works as expected, mean is left uninitialised
>>> }
>>>
>>> void g(out float[M][M] corr) // works but assigns twice
>>> {
>>>     corr[] = float.init; // compiler inserted
>>>
>>>     // assign to each value of corr
>>> }
>>>
>>> //Error: found ')' when expecting '.' following void
>>> void h(out float[M][M] corr = void)
>>> {
>>>
>>> }
>>>
>>> is there a way to not assign to out variables?
>>
>> Try 'ref' instead of 'out'.
> 
> Hmm, I could, but ref doesn't signal intention like out does.

True. Please file an enhancement request.


More information about the Digitalmars-d mailing list