The test code #include <stdlib.h> class Test { public: int t; Test():t(1) {} };
Test ex_t; void Init() __attribute__ ((constructor)); void Init() { if(ex_t.t==0) abort(); } int main(void) { return 0; } aborted if compiled with gcc 4.3.2. If compiled with gcc 4.1.0 or 3.3.6 it proceed normally. As I understand, in first case the ex_t constructor called after function Init, but in second case the ex_t constructor called before function Init. I not found in documentation what case is right, so I think this is a bug. In my opinion, constructors of global variables must have more priority than __attribute__ ((constructor)) functions. Compilation command is simple: g++ -o test test.cpp -- Summary: Initialization of global variables and functions with constructor attribute. Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: uleysky at gmail dot com GCC build triplet: x86_64-unknown-linux GCC host triplet: x86_64-unknown-linux GCC target triplet: x86_64-unknown-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37667