Out parameters and initialization

Ivan Senji ivan.senji_REMOVE_ at _THIS__gmail.com
Fri Feb 24 09:38:47 PST 2006


Unknown W. Brackets wrote:
> The spec says:
> 
> out parameters are set to the default initializer for the type of it.
> 
> Which makes perfect sense, and works just fine.  The trick comes in when 
> I try some parameter initialization.  This really weirded me out at 
> first.  Example:
> 
> int main()
> {
>         uint i = 0;
>         test(i);
> 
>         return 0;
> }
> 
> void test(out uint i = 5)
> {
>         assert(i == 5);
> }
> 

Oops, missed this thread before.

Actually it kind of makes sence to me that this doesn't work.

But this does work, and is IMO a great feature:

int globalI = 0;

int main()
{
         uint i = 0;
         test();
	//globalI is now 5

         return 0;
}

void test(out uint i = globalI)
{
	i = 5;
         assert(i == 5);
}



More information about the Digitalmars-d-bugs mailing list