I am building a c++ library and I would need to initialize an openGL context for my program ( and other default resource objects ). Would it be good practice ( considering modern c++ semantics ) to "hide the Init. code" in a code chunk being called before main ? I cannot use static variables because I need to initialize things in a specific order ! (I cannot init a texture before openGLm or SDL !)
Here is my code :
#include <stdio.h>
#ifdef _MSC_VER // For msvc / msvc++ 2015
#define CCALL __cdecl
#pragma section(".CRT$XCU",read)
#define INITIALIZER(f) \
static void __cdecl f(void); \
__declspec(allocate(".CRT$XCU")) void (__cdecl*f##_)(void) = f; \
static void __cdecl f(void)
#elif defined(__GNUC__) for gcc / g++
#define CCALL
#define INITIALIZER(f) \
static void f(void) __attribute__((constructor)); \
static void f(void)
#endif
static void CCALL finalize(void)
{
/* Some king of delete / dispose here : like SDL_Quit, ... */
}
INITIALIZER(initialize)
{
/*
HERE IS THE STARTUP CODE ...
*/
}