gtpc2m0f | C/C++ Language Support User's Guide |
The atexit function records a function, pointed to by func that the TPF system calls at normal program termination. Normal program termination is the result of calling the exit function, returning from the main function, or calling the Basic Assembler Language (BAL) EXITC macro.
You can use the atexit function to register as many as 32 functions. The registered functions are called in reverse order. The registered functions must return to ensure that all registered functions are called.
Format
#include <stdlib.h> int atexit(void (*func)(void));
Normal Return
A zero value indicates that the function has completed successfully.
Error Return
A nonzero value indicates that the function has not completed successfully.
Programming Considerations
For example, if a process that runs on more than one I-stream calls atexit to register a function that accesses I-stream unique globals, the registered function must determine if it is running on the required I-stream and, if it is not, either switch itself to the correct I-stream or return without accessing the I-stream unique globals.
Examples
The following example uses the atexit function to call the goodbye() function at normal program termination.
#include <stdlib.h> #include <stdio.h> void goodbye(void); int main(void) { int rc; rc = atexit(goodbye); if (rc != 0) puts("Error in atexit."); return 0; } void goodbye(void) { /* This function is called at normal program termination. */ puts("The goodbye() function was called at program termination."); }
Output
The goodbye() function was called at program termination.
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.