External variables

The POSIX 1003.1 and X/Open CAE Specification 4.2 (XPG4.2) require that the C system header files define certain external variables. Additional variables are defined for use with POSIX or XPG4.2 functions. If you define one of the POSIX or XPG4 feature test macros and include one of these headers, the external variables will be defined in your program. These external variables are treated differently than other global variables in a multithreaded environment (values are thread-specific) and across a call to a fetched module (values are propagated). To access the global variable values (not thread specific), either C with the RENT compiler option or C++ must be used, and the SCEEOBJ autocall library must be specified during the z/OS® bind. The SCEEOBJ library must be specified before the SCEELKEX and the SCEELKED libraries. If the SCEEOBJ library is not specified first, then Language Environment® cannot find the external variables. Although there are no linker/binder errors or warnings, runtime errors can occur. Functions to access the thread-specific values of these variables are provided for use in a multithreaded environment.

For a dynamically called DLL module to share access to the POSIX external variables with its caller, the DLL module must define the _SHARE_EXT_VARS feature test macro. This is implemented in the current Language Environment runtime. For more information, see the section on feature test macros in z/OS XL C/C++ Runtime Library Reference.

When compiling code with the XPLINK or LP64 compiler options, all access to these external variables is resolved by dynamic linkage, using IMPORT control statements in the CELHS003 (CELQS003) member of the SCEELIB library. The SCEEOBJ library cannot be used when binding XPLINK executable modules. Because of this, the _SHARE_EXT_VARS (and subordinate) feature test macros need only be used with XPLINK to access the thread-specific values of these external variables without the explicit use of the thread-specific functions.

For more information on the header files referred to in the following sections, see z/OS XL C/C++ Runtime Library Reference.