This function gives a program an opportunity to evaluate specified code before it exits. The code should be protected from evaluation using the quote operator #.
Running this program...
#!/usr/cogent/bin/gamma
// Program name: exiting.g
// Demonstrates the atexit() function.
atexit(#princ("Exiting now.\n"));
princ("Started running...\n");
princ("Still running.\n");
exit_program(7);
princ("You missed this part.\n");
...gives these results:
[sh]$ exiting.g
Started running...
Still running.
Exiting now.
[sh]$
See the Starting Programs section in the Common Functions chapter (Tutorial One), or the Starting Programs section in the Common Functions for Any Program chapter (Tutorial Two) in the Cogent Tools Demo and Tutorials book for examples of this function used in context.