In order to ensure that some initialization code runs before main (using Arduino/avr-gcc) I have code such as the following:
main
class Init { public
You can use GCC's constructor attribute to ensure that it gets called before main():
main()
void Init(void) __attribute__((constructor)); void Init(void) { /* code */ } // This will always run before main()