Out parameters and initialization

Unknown W. Brackets unknown at simplemachines.org
Sat Feb 25 12:34:00 PST 2006


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.

That would be like this working:

int i = 0;
int j = i;

j = 5;
assert(i == 5);

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.

-[Unknown]


> Unknown W. Brackets wrote:
>> Where is that in the spec?  Why is that logical?
> 
> In the spec? As far as I know it isn't (at least I didn't see it anywhere).
> 
> Logical because:
> 
> void func(in int x = 7); means this is an input value and if I don't 
> suply one the default value will be 7.
> 
> void func(out int x = globalX);
> out tels us the value of x will be changed, the default value says if I 
> don't suply an argument change by default the value of variable globalX.
> 
> If you did something like:
> void func(out int x = 7)
> {
>   x = 11;
> }
> 
> the compiler will complain about 7 not being an l-value.
> It is the same reason why you can't call the above function like 
> func(11); 11 can not be assigned to.
> 
> The above effect can be/(should be able to be) achieved by
> typedef int int7 = 7; or something like this.
> 
> I hope this is the way it is ment to work  and not some crazy bug 
> because I'm really starting to like this feature.
> 
>>



More information about the Digitalmars-d-bugs mailing list