Answer the question
In order to leave comments, you need to log in
How to execute actions before main function is called (header-only solution)?
I'm trying to write my own class registration system for C++. This is necessary to automate polymorphic serialization in C ++ (save and load objects through a pointer to the base class).
Registering classes requires certain steps to be taken before the main() function is run. This can be done by calling the global variable constructors. For example, like this:
#define COMBINE1(X,Y,Z) X##Y
#define COMBINE(X,Y,Z) COMBINE1(X,Y,Z)
//-----------------------------------------------------------------------------
#define BEFORE_MAIN_START_DEFFERED_TASK_0_ARG(M_TaskID,\
M_TaskType, M_Priority)\
class M_TaskID {\
public:\
M_TaskID() {\
sBeforeMainStart.addTask(\
new M_TaskType(), M_Priority);\
}\
} s##M_TaskID;
//-----------------------------------------------------------------------------
#define BEFORE_MAIN_START_DEFFERED_TASK_1_ARG(M_TaskID,\
M_TaskType, M_Arg1, M_Priority)\
class M_TaskID {\
public:\
M_TaskID() {\
sBeforeMainStart.addTask(\
new M_TaskType(M_Arg1), M_Priority);\
}\
} s##M_TaskID;
//-----------------------------------------------------------------------------
#define BEFORE_MAIN_START_DEFFERED_TASK_2_ARG(M_TaskID,\
M_TaskType, M_Arg1, M_Arg2, M_Priority)\
class M_TaskID {\
public:\
M_TaskID() {\
sBeforeMainStart.addTask(\
new M_TaskType(M_Arg1, M_Arg2), M_Priority);\
}\
} s##M_TaskID;
//-----------------------------------------------------------------------------
#define PERFORM_BEFORE_MAIN_START_DEFFERED_ACTIONS()\
sBeforeMainStart.performTaskQueue();
Answer the question
In order to leave comments, you need to log in
TLS-callback and use - www.unknowncheats.me/forum/c-and-c/84146-tls-callb... or stackoverflow.com/questions/14538159/about-tls-cal...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question