on_exit
Objectives
We would like to :
- Understand the on_exit exit handler.
Notes
- The last notes were getting too long.
- Still chapter 25
- We can register a handler multiple times.
- atexit has some problems:
- You do not know the exit status in the call, so you can't take actions based on this.
- You have no way to pass data to the function.
-
int on_exit(typeof(void (int , void *)) *function, void * arg)
- requires stdlib
- We are passing a function pointer to a function that
- takes an int and a void*
- returns nothing.
- Returns 0 on success and not zero on failure.
- Requires some nasty casting.
- See exit2.cpp