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 / Functions and GDK

Author
Message
Indicium
16
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 15th Dec 2010 21:11 Edited at: 15th Dec 2010 21:38
Hello! I've finally got DarkGDK installed I've had a few problems trying to get it to work with Visual Studio 2010 and the February 2010 SDK, but I finally gave in, uninstalled everything and used the 2008 compiler, and the August 2007 sdk.

Anyways, it's nice to have it finally working, I've made a simple 'Spinning Cube program', and now I'm trying to get functions to work. They don't work as I expect. The only programming languages I've used are dbpro, php and a little of python, whenever I've declared functions in these languages they've always been at the end of the program/script.

Now that I'm trying to use c++ functions, I get an error placing them at the end of the source. I'm trying to create a simple timer based movement function with this code:



Upon compiling this code I get an error saying ''tbm': identifier not found'. But if I place it at the start, just after my variable declarations, it compiles fine. (Although doesn't work as expected, not sure why atm EDIT: the tbm function was outside the loop, hehe )

So, why question is, do I have to declare all functions at the start of a program?

On top of this, I'm also wondering why all GDK commands must be in the void DarkGDK (void) brace, the tutorials don't mention anything about that.

Thanks

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 15th Dec 2010 22:08 Edited at: 15th Dec 2010 22:09
You need to declare functions before they are used. If you don't want to put the whole function before the tbm() call, then place a forward declaration at the beginning of the program, which means just the header of the function:



From this, the compiler knows, when it reaches the tbm() line, that this is a call to a function which will be defined somewhere later.

When your project is composed of several files, then this will not be a problem because all function declarations will be in a header file which is #included into the main program. Usually you have this ordering issue only in the main module. (And of course, with any other functions which are local to a file and not "advertised" in the header.)

The "void DarkGDK (void){" is the entry point of the program. All programs have an entry point (the function with which program execution must begin). The format of this function depends on what type of program you are writing, e.g. a console (text) program and a Windows program have different main functions. Dark GDK replaces the Windows program entry point with its own main function.
Indicium
16
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 15th Dec 2010 22:31
Ah, thank you so much, as you can probably tell, I've never used c++ before. :p

I'm having a bit of a problem with my current code, it seems to get stuck in a sort of never ending loop... and prints the value "7008"

Could you take a look and see if you can see any obvious problems?



Thank you

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 16th Dec 2010 00:51 Edited at: 16th Dec 2010 00:54
I don't think this is your code, its a bug in GDK I think.
The following works:



Something about a corruption on the heap that affects the first variable you declare if you make a mistake, I think the latest GDK has fixed this issue.

A better fix is to not create an object with an ID of 0.

Indicium
16
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 16th Dec 2010 03:24
Quote: "A better fix is to not create an object with an ID of 0."


Ah, of course, how on earth did I miss that one?

Thanks, much appreciated.

Dar13
16
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 17th Dec 2010 01:53
Also, don't use dbStr() like you did in this line
. It causes a memory leak(very bad!!). One way to fix this is like :


Although that code creates and deletes the char pointer every time the loop runs, you no longer permanently lose memory(until reboot).


Indicium
16
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 18th Dec 2010 15:56
Thanks for the advice I take it there will be a lot of stuff I'll have to get used to?

Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 18th Dec 2010 20:47
Question of interest. Are you trying to make a port of Project Atomic?

http://ref.darkgdk.us/ <- Online DarkGDK Refernece. More content coming soon.
Dar13
16
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 18th Dec 2010 22:58
Not really, just getting used to OOP and C++'s syntax was the hardest for me.


Indicium
16
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 19th Dec 2010 22:36
Quote: "Are you trying to make a port of Project Atomic?"


The Project Atomic link in my sig is pretty much dead, I am working on an RTS that I plan to port at some point though

Quote: "just getting used to OOP and C++'s syntax was the hardest for me."


I'm glad to hear it, I have a little experience with it through PHP, but I'm still having a little trouble, thanks.

Login to post a reply

Server time is: 2024-09-28 14:11:17
Your offset time is: 2024-09-28 14:11:17