www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Unnamed parameter with default value

reply =?UTF-8?B?Ikx1w61z?= Marques" <luis luismarques.eu> writes:
Is there any particular reason why this is accepted? (I
introduced it by mistake):

      void foo(int = 3) {}

I guess it could be useful to ensure binary compatibility when
you expect to add the parameter later?
Jun 17 2014
next sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 17 Jun 2014 11:15:43 -0400, Lu=C3=ADs Marques <luis luismarques.=
eu>  =

wrote:

 Is there any particular reason why this is accepted? (I
 introduced it by mistake):

       void foo(int =3D 3) {}

 I guess it could be useful to ensure binary compatibility when
 you expect to add the parameter later?
Of course this should be accepted. Omitting the name has nothing to do = with the API, but has to do with the fact that the implementation doesn'= t = use it. An implementation may be constrained by a base class or by some = = duck-type requirement even though it doesn't use the parameter. -Steve
Jun 17 2014
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 17 Jun 2014 11:19:46 -0400, Steven Schveighoffer  
<schveiguy yahoo.com> wrote:

 Of course this should be accepted.
I want to apologize, that came out sounding condescending, I didn't mean it that way. -Steve
Jun 17 2014
parent =?UTF-8?B?Ikx1w61z?= Marques" <luis luismarques.eu> writes:
On Tuesday, 17 June 2014 at 15:25:22 UTC, Steven Schveighoffer
wrote:
 Of course this should be accepted.
I want to apologize, that came out sounding condescending, I didn't mean it that way.
No problem. Thanks for clarifying this for me, I was just wanted to understand if/why this was useful (most likely scenario), or if it was similar to those cases where the frontend accepts nonsensical declaration qualifiers.
Jun 17 2014
prev sibling parent "Maxim Fomin" <maxim maxim-fomin.ru> writes:
On Tuesday, 17 June 2014 at 15:15:44 UTC, Luís Marques wrote:
 Is there any particular reason why this is accepted? (I
 introduced it by mistake):

      void foo(int = 3) {}

 I guess it could be useful to ensure binary compatibility when
 you expect to add the parameter later?
Actually there is nothing strange because current implementation technically does not remove variable names, it generates implicit ones. This compiles: void foo(int = 0) { _param_0 = 1; } and is equivalent to void foo(int _param_0 = 0) { _param_0 = 1; } It is not a wise design decision which is aimed to support some case, it is just technical consequence of implementation. And I don't think that it has anything to do with binary compatibility, because both parameter names and default arguments exists only in compile time.
Jun 17 2014