Special considerations for reentrant modules

A simple freestanding routine that does not require C library functions is shown in Figure 1. This routine uses the exit() function, which is normally part of the C library but (like sprintf()) is available to freestanding routines without requiring the dynamic library. This routine is not naturally reentrant, but the resulting load module is reentrant.
Figure 1. Sample reentrant freestanding routine
#include <stdlib.h>

int main() {
    static int i[5]={0,1,2,3,4};
    exit(320+i[1]);
}

The JCL required to build and execute this routine is shown in Figure 2. The bracketed numbers in the figure refer to the comments that follow.

Figure 2. Building and running a reentrant freestanding MVS™ routine
//PRLK      EXEC   PGM=EDCPRLK,PARM='MAP,NCAL'                 [Figure 2-1]
//STEPLIB   DD     DSN=CEE.SCEERUN,DISP=SHR
//SYSMSGS   DD     DSN=CEE.SCEEMSGP(EDCPMSGE),DISP=SHR
//SYSOUT    DD     SYSOUT=*
//SYSMOD    DD     DSN=&&OBJ,SPACE=(TRK,(1,1)),UNIT=SYSDA,
//                 DCB=(BLKSIZE=400,RECFM=FB,LRECL=80),
//                 DISP=(MOD,PASS)
//SYSIN     DD     DSN=RETS321.OBJ,DISP=SHR                    [Figure 2-2]
//*
//*
//LKED      EXEC   PGM=HEWL,PARM='MAP,XREF,LIST'
//SYSUT1    DD     SPACE=(CYL,1),UNIT=SYSDA
//PRELINK   DD     DSN=&&OBJ,DISP=(OLD,DELETE)                 [Figure 2-3]
//SYSLIN    DD     *
 INCLUDE SYSLIB(EDCXSTRT)                                      [Figure 2-4]
 INCLUDE PRELINK                                               [Figure 2-5]
 INCLUDE SYSLIB(EDCXEXIT)                                      [Figure 2-6]
 INCLUDE SYSLIB(EDCRCINT)                                      [Figure 2-7]
/*
//SYSPRINT  DD     SYSOUT=*
//SYSLMOD   DD     DSN=&&GOSET(GO),
//                 UNIT=SYSDA,SPACE=(TRK,(1,1,1)),
//                 DISP=(NEW,PASS)
//SYSLIB    DD     DSN=CEE.SCEESPC,DISP=(SHR,PASS)
//          DD     DSN=CEE.SCEELKED,DISP=(SHR,PASS)
//GO        EXEC   PGM=*.LKED.SYSLMOD