ld Manual

Introduction to ld
ld Manual529650.001
1-24
Declaration and Definition
Declaration and Definition
For data items shared across compilation units the difference between a declaration
and a definition is important.
Except for data that is exported from a user library, every data item must be defined at
least once when ld is building a loadfile. (A data item that will come from a DLL must
not be defined within the program using the DLL.) If a data item is never defined, you
will get a run-time error when you execute your program. If you get such an error,
change your pTAL, C, or C++ source code so that the data item is defined in one of
your compilation units. For example, you might need to provide a definition in one of
your C compilation units, or use the EXPORT_GLOBALS directive for your pTAL
compilation.
Data items defined in multiple COBOL or pTAL compilation units can be initialized
more than once, but all initial values for the same data item must be the same. Only
one C compilation unit is allowed to initialize a given data item.
ld does not perform type checking of symbols shared across compilation units. When
a data item is defined more than once, ld checks only that the size is the same in all
the definitions.
The body of a procedure is its definition, and only one copy of that body can exist. It is
acceptable, however, for a body to be absent (the same is true for data, which—like
procedures—can be found in run-time libraries). If the body does not exist, the
operating system searches for the procedure at run time in the system library or a user
library.
You can use the noft utility to examine symbol declarations and definitions in object
files. For more information, see the noft Manual.
Definition The compiler allocates space for the data item, possibly giving it an
initial value.
Declaration A compilation unit recognizes a data item, so the code can refer to it,
but this compilation unit has not allocated space for it.
Table 1-5. Declarations and Definitions by Language
Language Declarations Definitions
C
C++
A data item is considered a
declaration if it is external and has no
initial value
Data items that are not external,
have initial values, or both
COBOL No provision for declarations All data items
pTAL A data item is considered a
declaration if the compiler directive
EXPORT_GLOBALS is not set
Data items defined when the
compiler directive EXPORT_GLOBALS
is set