#pragma fini

Category

Object code control

Purpose

Specifies the order in which the runtime library calls a list of functions after main() completes or exit() is called.

For shared libraries, the fini functions are called when the shared library is loaded from memory. For example, when using dynamic loading, this happens at the point when dlclose() is called.

Syntax

Read syntax diagramSkip visual syntax diagram
                       .-,-------------.      
                       V               |      
>>-#--pragma--fini--(----function_name-+--)--------------------><

Usage

Any function that is specified in the pragma should have return type void (for example, void fA(); ) and take no parameters. Functions that have a non-void return type are accepted but the return value is discarded.

Functions that take parameters are ignored with a warning since the parameters would contain garbage values.

Within the same compilation unit, the list of functions in pragma fini are called in the order specified. Similarly, within the same compilation unit, functions specified in more than one pragma fini are called in the order in which the pragmas are encountered in the source.

In general, the order of static termination across files and across libraries is nonstandard and therefore, a non-portable behavior. It is not advisable to build any dependency on this behavior. The order of functions across files is undefined, even when using the -Wm option.

When mixing C and C++ files, the relative order of init or fini functions in C files with respect to the static constructors/destructors in C++ files is undefined. The -qunique option can interact with pragma fini.

Note: A C++ invocation, such as xlC or the redistributable tools linkxlC or makeC++SharedLib must be used at link time.

Related information