Non-local control structures

Most of the time in computer programming, causes are linked to effects by code at the "cause" point - i.e. if A should cause B then the routine that implements A should call the routine that implements B.

Sometimes, however, there is a need for effects to happen as a result of causes which don't know about those effects. The obvious example is COMEFROM but there are serious examples as well. Breakpoints and watchpoints when you're debugging is one, Database triggers are another.

A more subtle example is the humble destructor in C++ (which I have written about before) - it's effect is non-local in the sense that if you construct an automatic object in a scope, code will automatically run when control passes out of that scope. It's still a local effect in that the cause and the effect are in the same scope, but it's non-local in the sense that there is no explicit code at the point where the destructor is run.

Leave a Reply