libmoost
|
00001 /* vim:set ts=3 sw=3 sts=3 et: */ 00036 #ifndef MOOST_COMPILER_ATTRIBUTES_CONSTRUCTOR_HPP__ 00037 #define MOOST_COMPILER_ATTRIBUTES_CONSTRUCTOR_HPP__ 00038 00039 #include "../pragmas.hpp" 00040 00060 #if defined( __GNUC__ ) 00061 00062 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 00063 // Constructor attribute support for gcc 00064 #define constructor__(name) \ 00065 struct name ## __ \ 00066 { \ 00067 static inline void name(void); \ 00068 static void __attribute__ ((constructor)) init(void) \ 00069 { \ 00070 static int once = 1; \ 00071 if(once) { name (); --once; } \ 00072 } \ 00073 private: name ## __(); \ 00074 }; \ 00075 void name ## __::name(void) 00076 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 00077 00078 #elif defined ( _MSC_VER ) 00079 00080 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 00081 // Constructor attribute support for Visual Studio 00082 #pragma section(".CRT$XCU", read) 00083 #define constructor__(name) \ 00084 struct name ## __ \ 00085 { \ 00086 static inline void name(void); \ 00087 static void init(void) \ 00088 { \ 00089 static int once = 1; \ 00090 if(once) { name (); --once; } \ 00091 } \ 00092 private: name ## __(); \ 00093 }; \ 00094 __declspec(allocate(".CRT$XCU")) \ 00095 void (__cdecl*name##_)(void) = &name ## __::init; \ 00096 void name ## __::name(void) 00097 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 00098 00099 #else 00100 #error "Constructor attribute is not supported" 00101 #endif 00102 00103 #endif // MOOST_UTILS_COMPILER_HPP__