Can't compile the code

Maxim Fomin maxim at maxim-fomin.ru
Sun Apr 28 13:10:41 PDT 2013


On Sunday, 28 April 2013 at 18:40:20 UTC, bearophile wrote:
> Ali Çehreli:
>
>> The name of the parameter is omitted. Could have named it as 
>> 'p':
>>
>>    auto f = (bool p = false) {};
>
> OK. But is it syntactically allowed in D to omit the variable 
> name when there is a default argument? I have never seen it 
> before...
>
> Bye,
> bearophile

That's because currently no variable name means _param_XXX,
moreover it can be accessed.

int dummy;

void foo(ref int = dummy)
{
	_param_0 = -1;
}

void main()
{
	int x;
	foo(x);
	assert(x is -1);
}


More information about the Digitalmars-d-learn mailing list