www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can't compile the code

reply "Temtaime" <temtaime gmail.com> writes:
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).
Apr 28 2013
next sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
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
Apr 28 2013
prev sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Temtaime:

         auto f = (bool = false) {};
I don't understand this syntax. Bye, bearophile
Apr 28 2013
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
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
Apr 28 2013
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
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
Apr 28 2013
parent "Maxim Fomin" <maxim maxim-fomin.ru> writes:
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); }
Apr 28 2013