| |||
Home > The C and C++ Libraries > Tailoring the C library to a new execution environment > How C and C++ programs use the library functions |
This section describes specific library functions that are used to initialize the execution environment and application, library exit functions, and target-dependent library functions that the application itself might call during its execution.
The entry point of a program is at __main
in
the C library where library code does the following:
Copies nonroot (RO and RW) execution regions from their load addresses to their execution addresses.
Zeroes ZI regions.
Branches to __rt_entry
.
If you do not want the library to do this, you can define
your own __main
that branches to __rt_entry
as
in Example 4.1.
The library function __rt_entry()
runs
the program as follows:
Calls __rt_stackheap_init()
to
set up the stack and heap.
Calls __rt_lib_init()
to initialize
referenced library functions, initialize the locale and, if necessary,
set up argc
and argv
for main()
.
For C++, calls the constructors for any top-level objects.
Calls main()
, the user-level
root of the application.
From main()
, your program might call,
among other things, library functions. See Library functions called from main() for more information.
Calls exit()
with the value
returned by main()
.
The function main()
is the user-level
root of the application. It requires the execution environment to
be initialized, and that input/output functions can be called. While
in main()
the program might perform one of
the following actions that calls user-customizable functions in
the C library:
Extend the stack or heap. See Tailoring the runtime memory model.
Call library functions that require a callout to
a user-defined function, __rt_fp_status_addr()
or clock()
for
example. See Tailoring other C library functions.
Call library functions that use LOCALE
or CTYPE
.
See Tailoring locale and CTYPE.
Perform floating-point calculations that require the fpu or fp library.
Input or output directly through low-level functions, putc()
for
example, or indirectly through high-level input/output functions
and input/output support functions, fprintf()
or sys_open()
for
example. See Tailoring the input/output functions.
Raise an error or other signal, ferror
for
example. See Tailoring error signaling, error handling,
and program exit.