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

Table Of Contents
HP C Implementation-Defined Behavior
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
A-16
G.3.2 Environment
G.3.2 Environment
No library facilities are available to a freestanding program.
In a freestanding environment, program termination is:
The program termination phase of execution begins when a program returns from
the function main, calls the exit() library function, or calls the
terminate_program() library function. In each case, the C library flushes all file
buffers, closes all open files, and causes the process to complete with a certain
completion code, depending on what caused the termination.
When the process returns from main with no return value, the process stops with a
completion code of 0, normal termination.
When a program calls exit() or terminate_program(), the process
completes with normal or abnormal termination depending upon the completion
code assigned to the status or options parameters, respectively.
HP TNS C allows the declaration of up to three parameters to the program's function
main.
int main(int argc, char *argv[], char *env[])
When declaring parameters to the function main, note:
The parameters to main are optional; there can be no parameters, argc and argv,
or all three parameters. env alone is not allowed.
The identifiers argc, argv, and env are simply the traditional names of the three
parameters to main; any identifiers may be used.
The elements of the environment array env point to strings of the form:
param-name=param-value
where param-name is the name of the environment parameter, and param-
value is its value.
These are valid interactive devices:
Parameters Description
argc An integer value specifying the number of elements in the argument
array argv
argv The argument array. Each element (except for the last) points to a
null-terminated string. argv[0] points to the fully qualified name of
the executing program, the executing program name being that used
in the RUN command. Each of the elements argv[1] through
argv[argc-1] points to one command-line argument; argv[argc]
has the pointer value NULL.
env The environment array. Each element (except for the last) points to a
null-terminated string containing the name and value of one
environment parameter. The last element has the pointer value NULL.