I think you are just curious as a beginner that you can define multiple mains in your program. Understand that main is a special function. You cannot have several mains in your program. If you define main1 or main2 they are always going to be ordinary functions. And execution of programs will start with main(). Though there are constructors that are called before main and you can explicitly define a function to be one, but in general/default cases main is the entry point of the program.
But if you still want to call main1 before main here's how you can do:
#include <stdio.h>
int main1(void) __attribute__ ((constructor));// Note this line.
int main2(void) __attribute__ ((constructor));
int main2(void)
{
printf("Came to main2.\n");
}
int main1(void)
{
printf("Came to main1.\n");
}
int main(void)
{
printf("Came to main. \n");
}
Also note the order in which main1 and main2 are defined. main1 is defined after main2. Therefore the output is
Came to main1.
Came to main2.
Came to main.
Beware, this is a gcc specific thing.