With g++ 4.5.0 static initializers can be executed more than once. Here's how. Let a.cc contain the following code:
#include <stdio.h> struct A { A() { static int x = printf("x initialized at @%p\n", &x); } }; extern "C" void inita(); void inita() { A x; A y; } And let b.cc be the copy of a.cc where 'inita' has been renamed to 'initb'. Then make a shared library a.so from a.cc and b.so from b.cc. Finally, make a program that dynamically loads a.so and b.so and calls inita and initb functions. Since 'x' ends up as a unique global symbol, there will be only one object in the process, but the initialization code will be run twice (the address printed will be the same). -- Summary: Static initializers executed more than once when using unique global symbols Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ivan dot stankovic at avl dot com GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44059