Using main to immediately call another function?

Dec 11, 2013 at 7:19pm
Is it okay to use main as just the entry point and immediately skip to another function? Here's an example of what I mean.

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;

int someFunction();

int main(){
    someFunction();
}
int someFunction(){
    // do stuff
}


Sorry if this is a bit dumb, but I prefer to be cautious.
Last edited on Dec 11, 2013 at 7:21pm
Dec 11, 2013 at 7:26pm
Yes that is perfectly acceptable, and quite common.

Most of the programs I write have a very, very small main().
Dec 11, 2013 at 7:27pm
I would say no personally, but if you make the other function at least mimic main I would be more inclined to say yes. Just keep in mind you are changing an entry point that has been around for quite some time. And if all main does is call the other entry point that does sound a little silly to me. Here is how I would do it though:

1
2
3
4
5
6
7
8
9
int entry_func(int argc, char** argv)
{
    return 0;
}

int main(int argc, char** argv)
{
    return entry_func(argc, argv);
}
Topic archived. No new replies allowed.