Out parameters and initialization

Ivan Senji ivan.senji_REMOVE_ at _THIS__gmail.com
Sat Feb 25 01:14:44 PST 2006


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