Preinitializing a C program

Figure 1 is a sample preinitialized C program that shows how to do the following:
  • Establish the C environment using an INIT request
  • Pass runtime parameters to the C initialization routine
  • Set up a parameter to the C program
  • Repeatedly call a C program using the CALL request
  • Communicate from the C program to the driving program using a return code
  • End the C program using the TERM request

The parameters it expects are the file name in argv[1] and the return code in argv[2]. The C program printf()s the value of the return code, writes a record to the file name, and decrements the value in return code.

The assembler program that drives the C program establishes the C environment and repeatedly invokes the C program, initially passing a value of 5 in the return code. When the return code set by the C program is zero, the assembler program terminates the C environment and exits.

Program CCNGCA6 (Figure 1 ) does not include the logic that would verify the correctness of any of the invocations. Such logic is imperative for proper operations.

Program CCNGCA7 (Figure 2) shows how to use the preinitializable program.

Finally, Figure 3 shows sample program CCNGCA8.

Figure 3. Using the preinitializable program (CCNGCA8)
/* this example shows how to use a preinitializable program */
/* part 3 of 3 (other files are CCNGCA6 & CCNGCA7) */

#include <string.h>

#pragma  linkage(fetched, fetchable)

int fetched(int run_index, char *ffmsg) {
  sprintf(ffmsg,"Welcome to myfunc: Run index was %d.",run_index);
  return(0);
}