gargulak@mozart.convex.com (Tom Gargulak) (11/13/90)
I got the following example from the book by Barnes (pg. 183). Barnes claims that this program should raise the STORAGE_ERROR exception and I agree due to 11.4.1(10) in the LRM. A colleague believes that Barnes is mistaken and that it would be acceptable for the program to run forever. He claims it depends how the stack is implemeted. Barnes claims the following should happen: | n-3 B H | n-2 B H B | n-1 B H B H B V n * * * * * Invocation --------------------------------------->time B - executing in the procedure body for invocation n-m H - executing in the exception handler for invocation n-m * - a call which failed due to STORAGE_ERROR Does anyone know what should happen and why? Thanks, Tom --------------------------------cut here---------------------------- procedure P is begin P; exception when others => P; end;
bhanafee@ADS.COM (Brian Hanafee) (11/13/90)
In article <108637@convex.convex.com> gargulak@mozart.convex.com (Tom Gargulak) writes: >I got the following example from the book by Barnes (pg. 183). Barnes >claims that this program should raise the STORAGE_ERROR exception >and I agree due to 11.4.1(10) in the LRM. A colleague believes that >Barnes is mistaken and that it would be acceptable for the program >to run forever. He claims it depends how the stack is implemeted. [stuff deleted] > >procedure P is >begin > P; >exception > when others => > P; >end; I believe that there are three possible (implementation dependent) behaviours for this program: Case 1: The compiler generated code does not require any new storage for each new invocation of P. In this case, the program will not run out of storage, and may acceptably run forever. Case 2: If the implementation requires that each invocation of P uses some new storage (such as stack space), then eventually an invocation of P will cause a STORAGE_ERROR. The invocation of P from the handler will (presumably) cause a *new* STORAGE_ERROR to be raised. Under 11.4.1(10), this exception will cause the program to raise STORAGE_ERROR. Case 3: After STORAGE_ERROR is first raised, the program could detect that the invocation of P from the handler is erroneous, and raise PROGRAM_ERROR instead. ------------------------------------------------------------------------ Brian Hanafee | **Standard Disclaimer** Advanced Decision Systems | ------------------------------------------------------------------------
gargulak@mozart.convex.com (Tom Gargulak) (11/14/90)
[oops again] One thing I failed to mention. I assume that the program will raise a storage_error exception due to the infinite recursion. I realize some compilers can optimize this into a loop. So, assuming the exception occurs, will this program eventually terminate? Why? Thanks again, Tom