Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Microsoft equivalent to GCC option init_priority?

When compiling and linking a C++ library or program, there are no guarantees on the order of initialization of static C++ objects among translation units. GCC offers init_priority to solve the problem for static archives, shared objects and programs:

init_priority (priority)

    In Standard C++, objects defined at namespace scope are guaranteed to
    be initialized in an order in strict accordance with that of their
    definitions in a given translation unit. No guarantee is made for
    initializations across translation units. However, GNU C++ allows
    users to control the order of initialization of objects defined at
    namespace scope with the init_priority attribute by specifying a
    relative priority, a constant integral expression currently bounded
    between 101 and 65535 inclusive. Lower numbers indicate a higher
    priority.

(The static archive seems to be trickiest because it will (presumably) be linked by someone else).

What does Microsoft offer for controlling the order of initialization of static C++ objects among translation units?

like image 442
jww Avatar asked Aug 08 '15 23:08

jww


Video Answer


1 Answers

#pragma init_seg is probably the most similar documented equivalent.

like image 94
James McNellis Avatar answered Sep 21 '22 11:09

James McNellis