why scope(success)?

Regan Heath regan at netwin.co.nz
Tue May 9 21:39:30 PDT 2006


On Tue, 9 May 2006 22:36:03 -0400, Ben Hinkle <ben.hinkle at gmail.com> wrote:
>> Maybe... self documenting functions, listing all return values at the  
>> top?
>>
>> int foobar( ..etc.. )
>> {
>>   scope(success) return 1;
>>   scope(failure) return 0;
>>
>> }
>
> Does scope(failure) continue unwinding the stack? I wonder what the  
> behavior
> is of returning from a scope(failure).

Good question. No idea. :(

> I believe writing "scope(success) foo;" followed by the end of the  
> current scope is equivalent to just writing "foo;". Maybe I'm  
> misunderstanding the example.

You're right. For some reason I got it in my head that scope(success)  
happened when the function itself returned, as opposed to the current  
scope closing.

So, what about in this case:

int foobar( ..etc ..)
{
   if (a) scope(success) a.foo();
   //A: immediately after if
}
//B: at function return

when does a.foo() get executed? at A or B? I get the impression it's A.

Regan



More information about the Digitalmars-d mailing list