Share via


init_seg

C++ Specific —>

#pragma init_seg({ compiler | lib | user | "section-name" [, "func-name"]} )

Specifies a keyword or code section that affects the order in which startup code is executed. Because initialization of global static objects can involve executing code, you must specify a keyword that defines when the objects are to be constructed. It is particularly important to use the init_seg pragma in dynamic-link libraries (DLLs) or libraries requiring initialization.

The options to the init_seg pragma are:

compiler

Reserved for Microsoft C run-time library initialization. Objects in this group are constructed first.

lib

Available for third-party class-library vendors’ initializations. Objects in this group are constructed after those marked as compiler but before any others.

user

Available to any user. Objects in this group are constructed last.

section-name

Allows explicit specification of the initialization section. Objects in a user-specified section-name are not implicitly constructed; however, their addresses are placed in the section named by section-name.

func-name

Specifies a function to be called in place of atexit when the program exits. The function specified must have the same signature as the atexit function:

int funcname(void (__cdecl *)(void));

If you need to defer initialization (for example, in a DLL), you may choose to specify the section name explicitly. You must then call the constructors for each static object.

END C++ Specific