The extension "init_priority" doesn't work correctly on some platforms. Global static objects are not deinitialized in a proper order, as the following testcase shows. It is probably because of a linker bug.
----------------------------8<------------------------------ #include <stdio.h> struct A { A() { printf("A()\n"); } ~A() { printf("~A()\n"); } }; struct B { B() { printf("B()\n"); } ~B() { printf("~B()\n"); } }; struct C { C() { printf("C()\n"); } ~C() { printf("~C()\n"); } }; struct D { D() { printf("D()\n"); } ~D() { printf("~D()\n"); } }; static A a; static B b; static C c __attribute__((init_priority(101))); static D d; int main(int argc, char *argv[]) { return 0; } ----------------------------8<------------------------------ It produces: C() <= this is OK because of init_priority A() B() D() ~C() <= deinitialization order error ~D() ~B() ~A() But it should be: C() A() B() D() ~D() ~B() ~A() ~C() <= should be deinitialized here -- Summary: Invalid global deinitialization order Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: other AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: wyderski at ii dot uni dot wroc dot pl GCC host triplet: IA-32, GCC 4.0.0 (DJGPP package), Windows XP http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24472