Out parameters and initialization

Ivan Senji ivan.senji_REMOVE_ at _THIS__gmail.com
Sat Feb 25 13:28:50 PST 2006


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