How can I change the entry point "main" of my program ?
#include<stdio.h>
int main(int argc, char *argv[])
{
printf("%s\n","Hello world!");
return 0;
}
How can I change the entry point "main" of my program ?
#include<stdio.h>
int main(int argc, char *argv[])
{
printf("%s\n","Hello world!");
return 0;
}
gcc -o entry_test -Wl,-eother entry_test.c
#include<stdio.h>
int other(void){//can't use argc, argv
printf("Bye-Bye world!\n");
return 0;
}
int main(int argc, char *argv[]){
printf("%s\n","Hello world!");
return 0;
}
If you're using gcc, I found a thread that said you can use the -e command-line parameter to specify a different entry point; as BLUEPIXY stated see also :
Avoiding the main (entry point) in a C program
-see the following link for more details about "-e" option :
http://gcc.gnu.org/ml/gcc/2001-06/msg01959.html
Another way is to change the starting function is in the linker "start up" file.. linker may include some pre-main startup code in a file like start.o and it is this piece of code which runs to set up the C environment then call main (as in all embedded tool-chains). There's nothing to stop you replacing that with something that calls another function instead.
here is a terrific explanation for startup files:
What is the bootloader and startup code in embedded systems?
I voted this question up as it really may be useful for some embedded c developers.