Originally Posted By: the_clown
that would break when used in a library, too?

It would just break. Static functions are only visible to the current compilation unit and aren't shared. You can test this yourself by returning the pointer to the static variable and printing that in the callee, then do this from two compilation units and link it all together.

Here is my second snippet. It also uses static variables, and it's a tad longer.
Code:
class Initializer
{
public:
	typedef void (*Callback)();
	
	Initializer(Callback ctor, Callback dtor) :
		_dtor(dtor)
	{
		if(ctor) ctor();
	}
	
	~Initializer()
	{
		if(_dtor) _dtor();
	}
	
private:
	Callback _dtor;
};

#define RN_REGISTER_INITIALIZER(name, body) \
	namespace { \
		static void __RNGlobalInit##name##Callback() { body; } \
		static RN::Initializer __RNGlobalInit##name (__RNGlobalInit##name##Callback, nullptr); \
	}
#define RN_REGISTER_DESTRUCTOR(name, body) \
	namespace { \
		static void __RNGlobalDestructor##name##Callback() { body; } \
		static RN::Initializer __RNGlobalDestructor##name (nullptr, __RNGlobalDestructor##name##Callback); \
	}



Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com