Sign in to follow this  
phear-

Hiding main()

Recommended Posts

phear-    162
Just out of curiosity, I was messing with the Esenthal game engine and I was wondering how they hide the main() function. A typical basic esenthal game source would look like: (obviously you would put stuff within the functions)
void Create() {   }

void Init() {   }

void Pre() {   }

void Loop() {   }

void Post() {   }


Or something like that. Either way, you dont see or use the main() function. I dont have access to its source, so I figured I would ask here if anyone knew how to do such a thing (in C++). Thank you =)

Share this post


Link to post
Share on other sites
phear-    162
So they would declare main() in the main engine header file and then in the .cpp file they would have main() and call those functions? I didnt think that would work, which is why im posing this question. Thanks for the reply though =)

Share this post


Link to post
Share on other sites
Ravyne    14300
Yeah, it should work just fine. As long as they declare those functions the compiler won't complain about not finding implimentations, and as long as your implimentations match the signature they prescribe, the linker will take care of linking up the calls.

As a simple exercise, you could change the name of one of these functions, build the project, and see if it generates a linker error.

Share this post


Link to post
Share on other sites
Fenrisulvur    186
Quote:
Original post by phear-
So they would declare main() in the main engine header file

It wouldn't appear in the header. You've built programs out of multiple .cpp files before, right? And each one becomes an object file, you recall? And you only declared main() in one .cpp file, and didn't have to define it in any common header files for the other .cpp files to see it, right?

The only difference in this case is, instead of main() sitting in one of your object files, it's in one of the object files/libraries (probably the latter, I guess) of this engine you're using.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this