Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Where did int Main() go?

Author
Message
Infinity8
13
Years of Service
User Offline
Joined: 27th Feb 2011
Location:
Posted: 12th May 2011 23:07 Edited at: 13th May 2011 01:26
Hello all GDK developers new person here :p

Ive been coding in DPro for a short while, and made a reasonable little game template. I took a look at C++ and the darkGDK's higher speed so i thought id port it over :p

Well thats all beside the point, anyways here is my question:

On all the sites and books im reading to learn C++ it mentions that you NEED the int main() function for the program to run, without it you will get an error, however in all the darkGDK examples and templates its no where to be seen... so what happened? Where did it go?

Also a little overview of how im supposed to view the program running in darkGDK as opposed to DPro (initialisation -> main loop --> functions to be called in main loop) would be very much appreciated

Thx in advance for clearing this up :p
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 13th May 2011 01:32 Edited at: 13th May 2011 01:45
For the GDK, int main() is handled by the GDK itself. However, your program still needs a starting point for GDK to know where it begins. In short, for a GDK program, the void DarkGDK() function essentially replaces the int main() function that you have been reading about.

As to relating it to the DPro... Consider the following code snippet:



I hope this helps clarify things for you.

JTK

EDIT: Where did the original post go?!?!? Hmmm...
Infinity8
13
Years of Service
User Offline
Joined: 27th Feb 2011
Location:
Posted: 13th May 2011 01:49
Thank you that clears things up a bit

Am i right in assuming when i call DarkGDK im calling a class that contains int Main()?

Also i editted the original post a very little bit, forgetting that because im still a noob member it would delete it until mods approved the edit XD
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 13th May 2011 04:06
Quote: "Am i right in assuming when i call DarkGDK im calling a class that contains int Main()?"


Not exactly.

First off, GDK is a C-based interface (not C++) so no classes available (publicly anyway).

Secondly, DarkGDK() is a function called by the GDK's version of main() [remember, every C/C++ program needs a main() - that much you've read is true] - which is why you need to declare it [DarkGDK()] instead of main().

Regards,
JTK
Infinity8
13
Years of Service
User Offline
Joined: 27th Feb 2011
Location:
Posted: 13th May 2011 13:00
Okay, just one last question then

At which point does the DarkGDK version of main over? Because i thought the first thing the program does is search for an int Main() then run it, so DarkGDK has got to overwrite it somewhere before this happens.

And from this point, what would happen if you put both DarkGDK and int Main() into a program? which would run first? Or would it just die. (id try it myself but i still havent created a functioning C++ program :p)

Thank you, you have been very informative JTK
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 13th May 2011 18:22 Edited at: 14th May 2011 09:28
DarkGDK starts at WinMain, and call DarkGDK from there, it's more or less like:


now GDK is a group of libraries, in one header, it declares


and one library uses it, and because it's a library, the body of DarkGDK does not need to be defined in it, it could be defined in the code of the file which uses the library, and that is what's happening, your main.cpp (or whatever you made it) defines DarkGDK so the library can call it without linker errors

you are not defining any entry point in your source, you are just defining a regular function body

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 13th May 2011 18:23
When you compile the project your code along with any static libraries you are using (such as DarkGDK) are linked together to produce the executable. The main function just has to be somewhere in the executable. Since it is already in DarkGDK, it will be included just by linking with DarkGDK.

[b]

Login to post a reply

Server time is: 2024-11-19 10:30:03
Your offset time is: 2024-11-19 10:30:03