EXEC - compiling and executing C programs.

In general, multi-segment C programs should be compiled under (single segment) TSS. This is faster and easier than trying to do the whole thing in batch.

The command to compile a C source file is described in "expl nsc command". "expl nsc command" also explains how to compile a file in batch when it is absolutely necessary.

In general, you should compile all source modules into an LD object library first (using the "Update=" option of the compilation command). You can then link the modules in the LD object library with the command

nsc l=/mylib use=main o=/my_ru

This writes a complete run-unit into "/my_ru". This can then be executed with the JCL

$      run     rufile=userid/my_ru

A second approach is to link the program into a single OM with the command

nsc l=/mylib use=main o=/my_om format=linked_OM

This saves a bound OM into "/my_om". To run the program, use the JCL

$      lked
$      prmfl   o*,r,r,userid/my_om
$      data    n*
generate_ru
create_heaps -data 3K
$       run

When you execute a C program in native mode, you can supply a command line for the program in the file code "cz". This command line will supply the "argc" and "argv" program parameters for the program. For example,

$   data  cz
prog arg1 arg2 arg3

could be included in a program's JCL to pass command line arguments to the program.

I/O Considerations:

When a program refers to a file name (e.g. in a call to "fopen"), the name can take any one of several forms.

fc*xx
refers to the file associated with file code "xx". For example,
fopen("fc*ab","w");

opens file code "ab" for writing. If a file code opened for writing/appending does not already exist, a disk file will be created for that file code.

pathname
refers to the file with the given pathname. If the pathname contains no slashes, the file will be assumed to be a quick access file under the "userid" of the person running the program. The library will assign a free file code to the file when it is accessed.
pathname"fc*xx"
also refers to a file with the given pathname. However, the library will associate this file with the file code "xx" instead of choosing any file code. If the file code is already in use, an error will result.
$tty
refers to a TTY terminal or DAC line. More details are given later on.

By default, the library assumes disk files have GFRC format. This implementation of the C library can

Read Media Codes:  0, 1, 2, 3, 4, 6, 7, 8, 10
Write Media Codes: 0, 2, 3, 4, 6, 7, 10

By default, disk output is written in Media 6. The "_setmedia" function can change the default.

If a file code is associated with SYSOUT, the default is to write Media 7 on Report Code 72. This can be changed with "_setmedia".

In this implementation, the standard units are associated as follows:

stdin   -- file code I*
stdout  -- file code P*
stderr  -- file code P*

If you try to read "stdin" and have not defined file code I*, you will get end-of-file on "stdin".

Terminal~Handling:

If a file code is a DAC file code or associated with a terminal (i.e. has the name $TTY), it cannot be opened for reading until it has been opened for writing. It does not have to be opened for reading. If it is opened for reading, it must be closed for reading before it is closed for writing.

If you use "fopen" to open "$tty", the library will make a remote inquiry to determine the terminal name associated with the job's SNUMB. This means that if you execute a batch C program with the TSS command

jrn /jclfile:talk

the C program will connect to the terminal from which you issued the JRN command. The same sort of thing happens with DACs if they are defined in the JCL as

$      dac     xx

where "xx" is any file code. All such DACs plus "$tty" are associated with the same terminal. If one connection is closed, the others remain connected. If all are closed, a new open operation will perform the remote inquiry again.

If a DAC is defined in the JCL as

$      dac     xx,c

where "c" is any letter, a connection is established by obtaining the SNUMB of the current job and adding the specified letter. Thus

$      dac     yy,a
$      dac     zz,a

would both be connected to the same terminal.

If any terminal blocks, all terminals are blocked.

See Also:

expl nsc command

expl nsc lib _setmedia

Copyright © 1996, Thinkage Ltd.