Out parameters and initialization

Unknown W. Brackets unknown at simplemachines.org
Sat Feb 25 16:21:23 PST 2006


I understand it is useful.  Indeed, the following, if it worked, could 
possibly also be useful:

label:
// Never executed.
x = 1;

comefrom label;

That does not make it logical or consistent.  It makes it confusing and 
inconsistent.  Utility is not at all my concern.

In other words, you're essentially saying that this makes sense:

var2 = 2;
var1 = var2;
var1 = 1;
assert(var2 == 1);

If it were the other way around (var2 = var1) or if either variable had 
anything to do with C-style references or pointers, I might agree with 
you.  But even if they were classes, this would make no sense whatsoever.

It simply is not consistent with the rest of the language.  If it's 
going to work that way, it should do so everywhere.

-[Unknown]


> Unknown W. Brackets wrote:
>> Honestly, I understand the usefulness and where you're coming from, 
>> but if that's really intended it makes absolutely no logical sense to me.
> 
> And I honestly understand what behaviour you want. It happens that I 
> accidently found this behaviour and find it usefull.
> 
>>
>> That would be like this working:
>>
>> int i = 0;
>> int j = i;
>>
>> j = 5;
>> assert(i == 5);
> 
> Well with this I don't agree. int here isn't a reference type. (And I 
> know that you didn't really mean this as an equivalent example)
> 
>>
>> I realize that out is a reference/pointer type thing (automatically), 
>> but if there's no * there or anything, I don't want other variables to 
>> change.  It completely contradicts everything else in the language to 
>> me.... maybe it's just me, though.
> 
> I see it like this (maybe I'm repeating my self)
> 
> void func(in int a = 5)
> //func(), use default in value of 5
> 
> Default values are ment for cases when *no arguments* are specified:
> 
> void func(out int a = 7)
> {
>   a = 3;
> }
> 
> func();
> 
> //what is the above code doing? Assigning 3 to what? To 7? That isn't 
> possible because 7 is a constant.
> 
> The idea that a function
> void func(out int a = 7){}
> when called like this: func(b);
> is assigning 7 to b, contradicts the meaning of default in arguments.



More information about the Digitalmars-d-bugs mailing list