Avoiding the main (entry point) in a C program

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; so you could use func as your entry point, which would leave main unused.

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 calls main. 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.

Leave a Comment