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 / Need help with source code...

Author
Message
Game pro
20
Years of Service
User Offline
Joined: 21st Mar 2004
Location: Usa
Posted: 26th Aug 2008 01:07 Edited at: 26th Aug 2008 01:10
I'm completely lost here on why my source code isn't compiling...yes, I'm a noob at C++(not really, did some GBA programming) so I will need some help trying to figure this out.

It actually compiled up until I added the Main Func, btw I'm trying to port this code over from Darkbasic Pro.



Check out my dev forums at:
http://z15.invisionfree.com/ProjectRWP
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 26th Aug 2008 01:38 Edited at: 26th Aug 2008 01:38
I believe that the main GDK loop has to be in main().



Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 26th Aug 2008 06:27
No, it doesn't. Can you post the build log? Without seeing the errors, this code is pretty worthless. Is MainFunc() actually in 'Main.cpp'? Or are you using a function called 'main()'? If the latter is true, this could be conflicting with winmain(), as defined by 'DarkGDK.h'. Again, post the build log.


My site, for various stuff that I make.
Game pro
20
Years of Service
User Offline
Joined: 21st Mar 2004
Location: Usa
Posted: 26th Aug 2008 10:02 Edited at: 26th Aug 2008 10:11
Here is the build log.



Ah I caught one error I made. Dbsync() should be DbsyncOn() . That just leaves the MainFunc() identifier not found error.

Also to answer your question. Yes, MainFunc is a function located in Main.cpp .

Check out my dev forums at:
http://z15.invisionfree.com/ProjectRWP
pirogoth
16
Years of Service
User Offline
Joined: 6th Apr 2008
Location: Good Old California
Posted: 26th Aug 2008 10:44
This is actually a very simple issue. You'll notice you're calling MainFunc() before you've even defined the function. There are two ways to solve this. You can rearrange the order, defining MainFunc before DarkGDK(), or you can use a forward declaration. I'd vote for the later as a personal preference.


You'll see the forward declaration on lines 10/11. Your code should compile fine after that.

-Piro
Game pro
20
Years of Service
User Offline
Joined: 21st Mar 2004
Location: Usa
Posted: 26th Aug 2008 12:56 Edited at: 26th Aug 2008 12:59
Oh, thats not something we had to do in darkbasic pro. You could define the function at the end of your source code and it would still work. I didn't know that in C++ you need to define the function before it is called in the code. Weird.

Anyways, thanks for clearing that up.

Also, would the forward declaration still work if I wanted to have functions contained in another source file? Or is there something else I need to do there?

Check out my dev forums at:
http://z15.invisionfree.com/ProjectRWP
pirogoth
16
Years of Service
User Offline
Joined: 6th Apr 2008
Location: Good Old California
Posted: 26th Aug 2008 13:05
If you want to spread your functions out into other source files, yes forward declarations will work for you (in fact, that's what they are designed for). In general you'll create a header file with any function and class forward declarations you want accessible throughout your application.

-Piro
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 26th Aug 2008 17:52
Quote: "Oh, thats not something we had to do in darkbasic pro. You could define the function at the end of your source code and it would still work. I didn't know that in C++ you need to define the function before it is called in the code. Weird."


As others have said, you don't have to have the function defined before you make a call to the function. But when the function is called the compiler needs to know the footprint of the function so it knows what kind of arguments the function takes so it can set the stack properly and, if necessary, promote/demote data types. That's why you'd use a forward declaration, or prototype. It lets the compiler know what the function requires even if it doesn't know how it works.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office

Login to post a reply

Server time is: 2024-09-30 05:33:40
Your offset time is: 2024-09-30 05:33:40