Hiding main()

Started by
3 comments, last by Fenrisulvur 14 years, 5 months ago
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 =)
__________________________________________
Eugene Alfonso
GTP | Twitter | SFML | OS-Dev
Advertisement
What they probably do is have main exist in a library file so when you link your object code with Esenthal's the linker uses the main function in the library.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

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 =)
__________________________________________
Eugene Alfonso
GTP | Twitter | SFML | OS-Dev
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.

throw table_exception("(? ???)? ? ???");

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.

This topic is closed to new replies.

Advertisement