| Name || atexit
| Definition || atexit(e:expr(void)):expr(void).
| Example || atexit(print("foo=");print(foo);print('\n'))
| Defined in || ctrl.l
| Implementation || icode
| Description || Arange for the given expression to be evaluated when the program terminates. Note that there are four ways in which the program can terminate:|
(1) The code calls fatal.
(2) The code calls exit.
(3) The code reaches the end of the main program.
(4) The code deadlocks.
The atexit expression should be evaluated in cases (2)-(4) but not in case (1).
| Bugs || At present the atexit expression is not evaluated in case (3).
| See Also || exit, fatal.
| Note || Calling atexit for a second time causes the new expression to replace the original, not to be called in addition to it.|
The atexit expression may only access variables and functions declared at the global context. To be safe it is best to only call atexit from the global context.