Quote Originally Posted by fullmetalcoder View Post
I'm writing a C++ component that brings some requirements and after intense web browsing I did no find any clue...
[*]How to make some pieces of code called before main() and also static constructors?[*]How to make some pieces of code called after main() and also static destructors?
I've made this trick :

Qt Code:
  1. // GlobalClass.h
  2.  
  3. class GlobalClass
  4. {
  5. static GlobalClass * m_Instance;
  6. public :
  7. GlobalClass();
  8. ~GlobalClass();
  9.  
  10. // here stuff, if needed...
  11. };
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. // GlobalClass.cpp
  2.  
  3. GlobalClass * GlobalClass::m_Instances = 0;
  4.  
  5. GlobalClass::GlobalClass ()
  6. {
  7. // To avoid dlouble execution...
  8. assert ( m_Instance );
  9. m_Instance = this;
  10. // Before main stuff
  11. ...
  12. }
  13.  
  14. GlobalClass::GlobalClass ()
  15. {
  16. m_Instance = 0;
  17. // After main stuff
  18. ...
  19. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. GlobalClass GLOBALSTUFF;
  2.  
  3. int main ( int argc, char *argv[] )
  4. {
  5. // Here your code...
  6. }
To copy to clipboard, switch view to plain text mode 
[*]How to ensure that this hack is portable?[/LIST]

I think that's portable...

Thanks in advance for your help.
Not at all, if I hope this was useful for you...