I would suggest you to refer this link..
http://bhushanverma.blogspot.in/2010/09/how-to-call-function-before-main-and.html
For GCC compiler on Linux/Solaris:
#include
void my_ctor (void) __attribute__ ((constructor));
void my_dtor (void) __attribute__ ((destructor));
void
my_ctor (void)
{
printf ("hello before main()\n");
}
void
my_dtor (void)
{
printf ("bye after main()\n");
}
int
main (void)
{
printf ("hello\n");
return 0;
}
$gcc main.c
$./a.out
hello before main()
hello
bye after main()