### Run-Time Library Environments

The library environment is a section of information associated with and statically linked to the IBM C and C++ Compilers library itself. Your program has only one library environment if one of the following statements is true:

- It consists of a single executable module. By definition, a single module has only one copy of the IBM C and C++ Compilers library environment regardless of whether it links to the library statically or dynamically.
- Your executable module dynamically links to a single DLL that is statically bound to the IBM C and C++ Compilers run-time library and that uses the IBM C and C++ Compilers library functions. The executable module then accesses the library functions through the DLL.
- Your executable modules and DLLs all dynamically link to the IBM C and C++ Compilers run-time library.

If more than one of your modules is statically linked to the IBM C and C++ Compilers library, your program has more than one library environment. Because there is no communication between these environments, certain operations and functions become restricted:

- Stream I/O
  You can pass the file pointer between modules and read to or write from the stream in any module, but you cannot open a stream in one library environment or module and close it in another.
- Memory allocation
  You can pass the storage pointer between modules, but you cannot allocate storage in one library environment and free or reallocate it in another. For example, if storage is allocated in the single-thread library environment, you cannot reallocate or free it in the multi-threaded library environment.
- strtok, rand, and srand functions
  A call to any of these functions in one library environment has no effect on calls made in another environment.
- errno and doserrno values
  The setting of these variables in one library environment has no effect on their values in another.
- Signal and operating system exception handlers
  The signal handlers in one run-time environment are independent of those in another run-time environment. If a signal handler is registered in one environment and the signal occurs in a different run-time environment, the signal handler is not entered.
  If an exception handler is on the call chain when an exception occurs, it is called regardless of the run-time environment at the point of the exception.
- C++ exception handling
  If there is only one run-time environment, throw and catch work correctly across a dll-exe boundary. If the dll and executable modules have different environments, C++ exception handling semantics are not guaranteed.

In general, it is easier to use only one library environment, but it is not always possible. For example, if you are building a DLL that will be called by a number of applications, you should assume that there may be multiple library environments and code your DLL accordingly.

Stream Processing
Signals and Exceptions
Application Run-Time Environment Variables
Multithreaded Programs

Program Stream I/O