gtpc2m20C/C++ Language Support User's Guide

exit-Exit an ECB

This function ends a program.

Format

#include   <stdlib.h>
void       exit(int return_code);

return_code
Integer value indicating status.
TARGET(TPF) restriction

The return_code must be from 0 to 0x00FFFFFF. If nonzero, a system error bearing this identification number is issued before exiting.

Using the exit function is one way to cause normal program termination. (The other ways are calling the basic assembler language (BAL) EXITC macro and returning from the initial main function.) During normal program termination:

  1. All functions registered by the atexit function are called in last-in-first-out (LIFO) order.
  2. All open file streams and all open file descriptors are closed.
    Note:
    Sockets are not closed and must be closed explicitly by the application.
  3. All files created by the tmpfile function are deleted.
  4. Control returns to the host environment.
  5. If the entry control block (ECB) was created by a call to the system function, the tpf_cresc() function, or the BAL CRESC macro, the return_code value returns to the parent program, which resumes running after the child ECB has exited. Otherwise, the TPF system ignores the return_code value.
TARGET(TPF) restriction

Coding a nonzero return code as the argument will result in a system error dump.

Normal Return

The exit function does not return to its caller. This function gives control to the TPF system, which exits the ECB. If the ECB was created by a parent ECB through the system or tpf_cresc functions, or the BAL CRESC macro, the TPF system reactivates the parent ECB. For example, if program A calls program B through a call to the system function, and program B calls the exit function, program B exits and program A resumes running at the next sequential instruction (NSI).

Error Return

Not applicable.

Programming Considerations

Examples

The following example exits the ECB when processing is completed. No system error is issued.

#include <stdlib.h>
int main(void)

  ·
  ·
  ·
exit(0);

Related Information