Out parameters and initialization

Unknown W. Brackets unknown at simplemachines.org
Fri Feb 24 20:50:39 PST 2006


Where is that in the spec?  Why is that logical?

-[Unknown]


> 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