Tim's Hercules Page

Using GCCMVS

Now that GCCMVS is installed, it's time to try it out. The following example demonstrates compiling and executing a simple Hello World program.

GCCMVS does not ignore line numbers in columns 73 to 80. It will interpret them as code and will fail with return code 12. Line numbering can be disabled in RPF by typing NONUM in the editor. After turning off numbers, you still need to manually remove the numbers from any code you entered. This is only an issue when you type your code directly in RPF. If you copy the code with IND$FILE line numbers are not added.

The C programming language is case sensitive and generally lower case. By default, RPF will convert lower case characters to upper case characters. Type ASIS in the editor to leave character case as is.

Below is a simple C program that will be used to test GCCMVS. For simplicity this program will be stored in HERC01.TEST.CNTL(HELLO) since the HERC01 account and that particular dataset is available on all Turnkey systems.

#include <stdio.h>

int main()
{
     printf("Hello, MVS!\n");
     return 0;
}

Download Code (hello.c)

The job below will be used to compile the source code in the dataset specified by INFILE parameter and place the load module in the dataset specified by the OUTFILE parameter.

//HERC01C  JOB  CLASS=A,MSGCLASS=X,NOTIFY=HERC01,REGION=9216K
//GCCPRC  EXEC  PROC=GCCMVS,OUTFILE='HERC01.TEST.LOADLIB(HELLO)',
//             INFILE='HERC01.TEST.CNTL(HELLO)'
//COMP.SYSPRINT DD SYSOUT=*,DCB=(LRECL=132,BLKSIZE=132)
//LKED.SYSIN DD *
 INCLUDE SYSLIB(MVSSTART)
 INCLUDE SYSLIB(START)
 INCLUDE SYSLIB(MVSSUPA)
 INCLUDE SYSLIB(STDIO)
 INCLUDE SYSLIB(STDLIB)
 INCLUDE SYSLIB(CTYPE)
 INCLUDE SYSLIB(STRING)
 INCLUDE SYSLIB(TIME)
 INCLUDE SYSLIB(ERRNO)
 INCLUDE SYSLIB(ASSERT)
 INCLUDE SYSLIB(LOCALE)
 INCLUDE SYSLIB(MATH)
 INCLUDE SYSLIB(SETJMP)
 INCLUDE SYSLIB(SIGNAL)
 ENTRY @@MVSTRT
 NAME HELLO(R)

Download JCL (compile.jcl)

Besides including the C headers in your source code, they must also be included in the SYSIN DD of the linkage editor. In this case, more includes are used than required, but the list is presented for completeness.

Finally, run the program.

//HERC01C  JOB  CLASS=A,MSGCLASS=X,NOTIFY=HERC01
//EXECGO   EXEC PGM=HELLO,REGION=5000K
//STEPLIB  DD   DSN=HERC01.TEST.LOADLIB,DISP=SHR
//SYSPRINT DD   SYSOUT=*,DCB=(LRECL=132,BLKSIZE=132)
//SYSABEND DD   SYSOUT=*
//SYSIN    DD   DUMMY

Download JCL (run.jcl)

You can view the output of the program with the RPF Output processor (option 3.6). At the end of the output you should see something like this:

IEF375I  JOB /HERC01C / START 06241.2143
IEF376I  JOB /HERC01C / STOP  06241.2143 CPU    0MIN 00.02SEC SRB    0MIN 00.01SEC
Hello, MVS!


Back