Figure 1E: Example written in CL
/* To compile: CRTBNDCL PGM(EXAMPLE1E) */
PGM
DCL VAR(&PTR) TYPE(*PTR)
DCL VAR(&SZ) TYPE(*INT) VALUE(16)
DCL VAR(&BASED_DATA) TYPE(*CHAR) LEN(16) STG(*BASED) +
BASPTR(&PTR)
/* allocate 16 bytes of storage from the heap */
CALLPRC PRC('malloc') PARM( (&SZ *BYVAL) ) RTNVAL(&PTR)
/* set the allocated storage */
CHGVAR VAR(&BASED_DATA) VALUE('abcdefghijklmnop')
/* deallocate storage */
CALLPRC PRC('free') PARM( (&PTR *BYVAL) )
ENDPGM