The VSI C and C++ Version 7.1 and higher compilers have a
/MAIN=POSIX_EXIT qualifier that defines the _POSIX_EXIT macro
and causes the main program to call __posix_exit instead of exit
when returning from the main program.
This qualifier should be used with programs ported from UNIX that
do not explicitly call exit and do not use OpenVMS specific exit
codes.
For older compilers, the following sample code can be used to
force the existing main module to have a different name so that a
simple main program will call it but force the exit status to be
through the __posix_exit call.
The replacement main function can be in a different module, so
that /DEFINE="main=real_main" is all that is needed for modifying
the build of the existing main function.
#define _POSIX_EXIT 1
#include <stdlib.h>
int real_main(int argc, char **argv);
/* Make sure POSIXized exit is used */
int main(int argc, char **argv)
{
int ret_status;
ret_status = real_main(argc, argv);
exit (ret_status);
}
#define main real_main
Unless your C program is intentionally using OpenVMS status codes
for exit values, it is strongly recommended that both the _POSIX_
EXIT macro be defined and, if needed, the /MAIN=POSIX_EXIT or the
alternative main replacement be used so that DCL, BASH, and the
accounting file get usable exit values.