https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37667

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Michael Uleysky from comment #2)
> The priority must not be same. The only method to interact constructor
> function with main is global variables. It is no reason to initialize global
> variables after constructor function. Anyway,
> 
> Test ex_t __attribute__ ((init_priority(102)));
> void Init() __attribute__ ((constructor(101)));

Because you have the wrong order, lower number is a higher priority which means
101/Init will always be first.

From
https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Common-Function-Attributes.html#index-constructor-function-attribute:

"However, at present, the order in which constructors for C++ objects with
static storage duration and functions decorated with attribute constructor are
invoked is unspecified. In mixed declarations, attribute init_priority can be
used to impose a specific ordering."

"A constructor with a smaller priority number runs before a constructor with a
larger priority"

Reply via email to