Private default function arguments
"Jérôme M. Berger"
jeberger at free.fr
Sat Jan 16 06:39:07 PST 2010
Robert Clipsham wrote:
> On 15/01/10 08:25, bearophile wrote:
>> int foo3(int x, private int depth=0) {
>> ...
>> foo3(x+1); // OK
>> foo3(x, depth + 1); // OK
>> ...
>> }
>> void main() {
>> int r = foo3(5); // OK
>> int r = foo3(5, 1); // Error
>> int r = foo3(5, 0); // Error
>> }
>
> Does this not achieve the same effect? (OK, the syntax is a bit more
> verbose, but it'd do the trick?)
>
> ----
> int foo3(int x)
> {
> static int depth = 0;
> foo3( x + 1 );
> depth++;
> foo3( x );
> }
> ----
Two words: stack overflow. Even if you fix your function to avoid
the stack overflow, this would fail in multithread environments (or
be too slow if depth is made thread local).
Jerome
--
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100116/fe33c132/attachment.pgp>
More information about the Digitalmars-d
mailing list