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:jeber...@free.fr
http://jeberger.free.fr
Jabber: jeber...@jabber.fr

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to