tstack.pp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. {$ifdef CPUAVR}
  2. { avr does not support an exitproc }
  3. begin
  4. end.
  5. {$else CPUAVR}
  6. {$S+}
  7. { Program to check that an infinite recursion
  8. does generate a RTE ... }
  9. {$R-}
  10. { make that recursion really infinite
  11. needs that range check is disabled }
  12. const
  13. level : longint = 0;
  14. function inf_rec(x : longint) : longint;
  15. begin
  16. inc(level);
  17. inf_rec:=x+inf_rec(x-1);
  18. end;
  19. const
  20. saveexit : codepointer = nil;
  21. x : longint = 0;
  22. {$S-}
  23. { the stack overflowed already so don't do much here and depend on stack_margin }
  24. procedure stack_check_exit;
  25. begin
  26. exitproc:=saveexit;
  27. if errorcode<>0 then
  28. begin
  29. Writeln('An error occurred at level ',level);
  30. if errorcode=202 then
  31. begin
  32. Writeln('Stack overflow correctly handled');
  33. erroraddr:=nil;
  34. errorcode:=0;
  35. exitcode:=0;
  36. end
  37. else if errorcode=216 then
  38. begin
  39. Writeln('RTL returns an RTE 216 on stack overflow');
  40. Writeln('Not perfect, but acceptable');
  41. erroraddr:=nil;
  42. errorcode:=0;
  43. exitcode:=0;
  44. end;
  45. end
  46. else
  47. begin
  48. exitcode:=1;
  49. errorcode:=1;
  50. end;
  51. exitproc:=saveexit;
  52. end;
  53. begin
  54. saveexit:=exitproc;
  55. exitproc:=@stack_check_exit;
  56. x:=inf_rec(5000);
  57. end.
  58. {$endif CPUAVR}