Is it possible to execute a function before main()
Yes it is possible if you are using gcc and g++ compilers then it can be done by using __attribute__((constructor))
Example:
#include
void beforeMain (void) __attribute__((constructor));
void beforeMain (void)
{
printf ("\nThis is before main\n");
}
int main ()
{
printf ("\nThis is my main \n");
return 0;
}