Thread overview
Can't compile the code
Apr 28, 2013
Temtaime
Apr 28, 2013
Ali Çehreli
Apr 28, 2013
bearophile
Apr 28, 2013
Ali Çehreli
Apr 28, 2013
bearophile
Apr 28, 2013
Maxim Fomin
April 28, 2013
int main() {
        auto f = (bool = false) {};

        f();
        return 0;
}

I can't compile this code on
DMD32 D Compiler v2.062

On windows. It says to me:
Error: expected 1 function arguments, not 0

On linux it seems to work(http://ideone.com/fsKYWR).
April 28, 2013
On 04/28/2013 01:53 AM, Temtaime wrote:
> int main() {
>          auto f = (bool = false) {};
>
>          f();
>          return 0;
> }
>
> I can't compile this code on
> DMD32 D Compiler v2.062
>
> On windows. It says to me:
> Error: expected 1 function arguments, not 0
>
> On linux it seems to work(http://ideone.com/fsKYWR).

It is probably one of the known issues with default delegate parameters:

  http://d.puremagic.com/issues/show_bug.cgi?id=3866

Ali

April 28, 2013
Temtaime:

>         auto f = (bool = false) {};

I don't understand this syntax.

Bye,
bearophile
April 28, 2013
On 04/28/2013 09:14 AM, bearophile wrote:
> Temtaime:
>
>>         auto f = (bool = false) {};
>
> I don't understand this syntax.
>
> Bye,
> bearophile

The name of the parameter is omitted. Could have named it as 'p':

    auto f = (bool p = false) {};

Ali

April 28, 2013
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
April 28, 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);
}