Chapter Contents |
Previous |
Next |
Linking C Programs |
As mentioned, input to COOL can be either an object data set, control statements, or both. COOL control statements are listed in COOL Control Statements. An explanation of each statement follows the table.
The ARLIBRARY Statement |
ARLIBRARY name[,name...]
COOL adds the libraries specified by the name parameters to the list of AR370 archives to be used as autocall input. Refer to Using AR370 Archives for additional information about using AR370 archives with COOL.
The INCLUDE Statement |
INCLUDE filename [,...]
The second format of the INCLUDE statement is the following:
INCLUDE libname(member[,member])[,...]
INCLUDE MAINPROG,MYSUBS(SUB1,SUB2),SYSSUBS(GLBLFNC)
An included object file can contain an INCLUDE statement.
The specified modules are also included, but any data in the including file
after the INCLUDE statement is ignored unless the
noinceof
option is specified.
On CMS, the _INCLUDE environment variable can be used to specify shared file system directories to be searched for included files. For information on the _INCLUDE environment variable, refer to Specifying Shared File System Directories.
The INSERT Statement |
INSERT symbol [,...]
The GATHER Statement |
The format of the GATHER control statement is
GATHER prefix [,prefix2... ]
where prefix is a one-to-six character symbol. The following statements are examples of valid GATHER control statements.
GATHER ABC GATHER INIT,TERM GATHER I_
In C, the following objects can create SDs, LDs, and ERs:
LD |
label definitions,
const extern
objects, and
extern
objects when the
norent
compiler option is in effect. |
ER |
references to functions, to
const extern
objects, and to
extern
objects when the
norent
compiler option is in effect. |
SD |
No C source construct can create
an SD that may be gathered. Note that COOL changes any underscore characters
(
'_'
) in a prefix to pound signs (
'#'
). This corresponds
to the compiler's changing of underscore characters in external names to pound
signs. |
COOL prints the gathered names in its listing file if
the
gmap
option has been specified. For a prefix with
one or more matching gathered names, COOL prints
GATHERED FOR PREFIX "xxxxxx": xxxxxxx1 xxxxxxx2 xxxxxxx3
where
xxxxxxx1
,
xxxxxxx2
, and so on, are
the gathered names. For a prefix for which no matching names were found, COOL
prints:
GATHERED FOR PREFIX "xxxxxx": (NONE)
For
each prefix, COOL creates a GATHER table. A GATHER table is a
const extern
structure with the following definition:
struct { int count; void *entry[N] } xxxxxx$T;
The
count
field contains the number of
gathered objects. If no names were found that matched the prefix, the count
field is set to 0.
entry
is an array of (4-byte) pointers
to the gathered objects. These pointers are in no particular order in the
array.
N
is the number of gathered objects.
xxxxxx
is the prefix that was used to select the objects. For example, if the items
in the table are
__local
function pointers whose names begin with
INIT
, then the GATHER table can be declared as follows:
const extern struct { int count; __local void (*func[0] )(); } INIT$T;
Note that
func
can be declared as
an array of length
0
, as shown above. This enables the
GATHER table to be declared such that the programmer does not need to know
the number of items in the array at compile-time.
dollars
compiler option.
Alternately, the table can be given some other variable name, and the
#pragma map
directive can be used to assign it the external name of
xxxxxx$T
.
For example, suppose a program contains declarations
for four functions whose names start with
init
:
init0001
,
init0002
,
init0003
, and
init0004
and no
declarations or definitions of functions whose names
start with
term
. Given the following control statement
GATHER INIT,TERM
INIT$T CSECT DC F'4' DC V(INIT0001) DC V(INIT0002) DC V(INIT0003) DC V(INIT0004) TERM$T CSECT DC F'0' END
Suppose a number of functions need to be invoked upon
entry to the main function of a program, and a number of other functions need
to be invoked before the main function returns. The programmer specifies that
these functions (and only these functions) will have names that begin with
the characters
init
or
term
, depending on whether
they are to be invoked upon program startup or termination, respectively.
The number of functions will be unknown at compile time, as will the complete
names. If all of the functions are located in the primary load module, they
can be called via
__local
function pointers. The following GATHER control
statement causes COOL to produce GATHER tables for these two sets of functions:
GATHER INIT,TERM
const extern struct { int count; __local void (*func[0] )(); } init$t, term$t; int main() { int i, rc; for (i = 0; i < init$t.count; i++) (*init$t.func[i] )(); . . . for (i = 0; i < term$t.count; i++) (*term$t.func[i] )(); return rc; }
For more information about
_ _local
function
pointers, refer to Local Function Pointers.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.