Is it possible to avoid the entry point (main) in a C program. In the below code, is it possible to invoke the func() call without calling via main() in the below program ? If Yes, how to do it and when would it be required and why is such a provision given ?
int func(void)
{
printf("This is func \n");
return 0;
}
int main(void)
{
printf("This is main \n");
return 0;
}
If you’re using gcc, I found a thread that said you can use the
-ecommand-line parameter to specify a different entry point; so you could usefuncas your entry point, which would leavemainunused.Note that this doesn’t actually let you call another routine instead of
main. Instead, it lets you call another routine instead of_start, which is the libc startup routine — it does some setup and then it callsmain. So if you do this, you’ll lose some of the initialization code that’s built into your runtime library, which might include things like parsing command-line arguments. Read up on this parameter before using it.If you’re using another compiler, there may or may not be a parameter for this.