[Issue 851] strange bug when a delegate access a member variable.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 12 01:46:06 PST 2007


http://d.puremagic.com/issues/show_bug.cgi?id=851


lio at lunesu.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #2 from lio at lunesu.com  2007-02-12 03:45 -------
This is not a bug.

This issue gets posted on the newsgroups at least once per month, and I'd
suggest you search the groups for more detailed information. It's not a bug:
nested functions are only valid inside the function where they are declared.
This is because those function expect the stack to be exactly the way it was in
that function. In your example, do_start is only valid inside the constructor.
You can create delegates to nested function, but these delegates are not valid
outside the function. When these delegates are invoked, the stack might be
different, which means the this-pointer cannot be found. 

As I said: the stack might be different. This is why it might work if the stack
is left intact. If you do something that changes the stack (like an extra
function call, or declare some variables) the stack will have changed and the
delegates will no longer work.

To solve your code, move the do_start to the class. Then, it will no longer
depend on the stack, but it gets the "this" pointer directly (instead of a
stack pointer) and you can safely create and return delegates to it.


-- 



More information about the Digitalmars-d-bugs mailing list