C/C++ Programmer's Guide (G06.27+, H06.03+)

Table Of Contents
Running and Debugging C and C++ Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
19-3
Program Initialization
Program Initialization
Your program begins execution when the operating system transfers control to your
program’s object code. Before executing the code, however, the C run-time library
initializes its run-time environment. The C run-time library also calls a CRE initialization
function.
The CRE initialization function establishes the CRE’s internal data structures, I/O
model, and so forth, in addition to shared facilities such as the user data heap. After
the CRE has established its environment and set up shared facilities, it calls a
language-specific initialization function for each language that is represented by a
routine in your program, except TAL and pTAL. Each language-specific initialization
function sets up its data structures and file I/O model for the language that it supports.
When the CRE completes initialization, it returns control to the C run-time library. The
run-time library completes its own initialization and returns control to your main
function, which begins executing the instructions in the program’s object code.
For Guardian processes, the C run-time library performs several additional initialization
tasks during the process startup phase, including:
Processing the startup message sent by the command interpreter
Processing any command interpreter PARAM or ASSIGN messages
Opening the standard input, output, and error files: stdin, stdout, and stderr
Invocation of the constructors for global and static variables in C++
As it performs these tasks, the C run-time library acquires detailed information
regarding the environment in which the process is executing. The library saves this
information in the argument array. The argument array contains program and argument
information extracted from the RUN command—namely, program-file and each of
the arguments in args-list.
For Guardian processes, the library also saves information in the environment array.
The environment array contains environment parameters from PARAM messages.
The Guardian C run-time library includes six functions that allow the retrieval of the
process startup message, the PARAM message, and the ASSIGN messages. For
more details, see Retrieving Startup Information on page 19-6.
The Standard Input, Output, and Error Files
In the Guardian environment, the CRE automatically opens three standard files: stdin,
stdout, and stderr. You can suppress the automatic opening of these files with the
NOSTDFILES pragma.
In the OSS environment, the standard files are controlled by the OSS file system, not
the CRE. For information on using the standard files in the OSS environment, see the
Open System Services Programmer’s Guide.