Show: Delphi C++
Display Preferences

#pragma exit and #pragma startup

From RAD Studio
Jump to: navigation, search

Go Up to Pragma Directives Overview Index

Syntax (See Pseudo-grammar)

#pragma startup FUNC [NN]
#pragma exit FUNC [NN]

Description

These two pragmas allow the program to specify function(s) that should be called either upon program startup (before the main function is called) or program exit (just before the program terminates through _exit).

The specified function name must be a previously declared function taking no arguments and returning void; in other words, it should be declared as:

void myfunc(void);

Then the #pragma would be:

#pragma startup myfunc

Specifying Priority

The optional priority parameter (NN) should be an integer in the range from 64 through 255:

  • The highest priority is 0.
  • Functions with higher priorities are called first at startup and last at exit.
  • If you do not specify a priority, it defaults to 100 for both BCC32 and Clang-enhanced C++ compilers.
Warning: Do not use priority values less than 64 with BCC32. Priorities from 0 through 63 are reserved for RTL startup and shutdown mechanisms. The exception for Clang-enhanced C++ compilers is described in the text below.

Unit Initialization Order in Applications Built with Clang-enhanced C++ Compilers

Note: Unit initialization order should take priority over #pragma startup order, but this is currently not implemented for Clang-enhanced C++ compilers.

Clang-enhanced C++ compilers do not use unit initialization order, and therefore exit routines that are run without a priority specification close before the main form closes. If you are using Clang-enhanced C++ compilers, you must specify the #pragma exit routine with priority 30 in order to guarantee that the exit routine runs after __ExitVCL (and to match the behavior of BCC32). For example:

 #pragma exit myfunc 30

See Also

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance