William Ricker wrote:
> Yes. longjmp was once not only less C code but far far quicker to unwind > a deep stack than the standard > return(-1) if rc < 0; # lather rinse repeat > in old C on old slow hardware without optimized stack instructions. The > return()'s register swizzling is far cheaper on today's hardware which > has support for such, so that is less true today. Doing an exception > throw in OO C++ or Java or even Perl requires MUCH MORE *implicit* work > as the exception propagates through the call stack checking at each > frame for potential catches and potential destructors for on-stack > objects being freed. As there are somewhat optimized implementations of "return", there are optimized implementations of exceptions which do not require stack-walking in order to find the handler code & frame. It is possible to maintain a separate "handler stack", for example -- numerous other approaches are possible, depending on the language constraints. The details vary. CPU support varies. Languages vary. What people are comfortable using varies. Perhaps a little code will say something: foo () { a = openFile("A"); if ( FAIL = a ) return FAIL; ...use a... b = openFile("B"); if ( FAIL = b ) { close(a); return FAIL; } ...use a & b... b = openFile("B"); if ( FAIL = c ) { close(a); close(b); return FAIL; } ...use a & b & c... ...And so on... close(c); close(b); close(a); } bar () { try { a = openFile("A"); ...use a... b = openFile("B"); ...use a & b... b = openFile("B"); ...use a & b & c... ...And so on... } finally { close(c); close(b); close(a); } } baz () { a = openFile("A"); if ( FAIL = a ) goto a; ...use a... b = openFile("B"); if ( FAIL = b ) goto b; ...use a & b... b = openFile("B"); if ( FAIL = c ) goto c; ...use a & b & c... ...And so on... c: close(c); b: close(b); a: close(a); return FAIL; } As the saying goes: there's more than one way. Suit yourself. _______________________________________________ Boston-pm mailing list Boston-pm@mail.pm.org http://mail.pm.org/mailman/listinfo/boston-pm