External variables

For more information on external variables, see z/OS XL C/C++ Programming Guide.

The POSIX 1003.1 and X/Open CAE Specification 4.2 (XPG4.2) require that the C system header files declare certain external (global) 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 global variables will be declared in your program. These global variables are treated differently than other global variables in a multi-threaded environment (values are thread-specific rather than global to the process) and across a call to a fetched module (values are propagated rather than module-specific). To access the global variables, you must use either C with the RENT compiler option, C++, or the XPLINK compiler option. If you are not using XPLINK, you must also specify the SCEEOBJ autocall library. The SCEEOBJ library must be specified before the SCEELKEX and the SCEELKED libraries in the bind step. If the SCEEOBJ library is specified after the SCEELKEX and SCEELKED libraries, the bind step will resolve the external variables to the user application, but the Language Environment® run time will not use those same external variables, and so runtime errors can occur. You are also able to access the external variables by defining the _SHARE_EXT_VARS feature test macro during the compile step (or the _SHR_name feature test macro corresponding to the variable names you are accessing). For further information on feature test macros, see z/OS XL C/C++ Runtime Library Reference. In this case, functions which access the thread-specific values of the external variables are provided for use in a multi-threaded environment. If you use the XPLINK compiler option for a 32-bit program, the global variables are resolved by import using the CELHS003 member of the SCEELIB data set. The thread-specific values are always used.

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. For more information, see the section on feature test macros in the z/OS XL C/C++ Runtime Library Reference.