I just realized that I have ended with the code bellow just to be able to do some initialization during startup. I am asking if I am missing something and there is some standard way to run some code during initialization, and especially if we can define the initialization order as required, because the initialization doesn't goes exactly as expected.
#define concat(a,b) a##b
#define autoname1(cnt) concat(autoname_,cnt)
#define autoname autoname1(__COUNTER__)
#define onStartupExecute_(func,structname) void func();\
struct structname{structname(){func();}} autoname;
#define onStartupExecute(func) onStartupExecute_(func,autoname)
With the above code when e.g. we define:
void someInitialization(){doSomething1;doSomething2;}
onStartupExecute(someInitialization)
the code produced by onStartupExecute
is:
struct autoname_12{autoname_12(){someInitialization();}} autoname_13;
and so during startup before main the code someInitialization
is executed.
I think there should be some more simple way to do it !