Jump to content
  • Advertisement
Sign in to follow this  
Pogo708

A little syntax help...

This topic is 5019 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is a pretty simple question. Right now, my code is like this: -Includes -Variable Definitions -Functions -Main Loop Now, I've seen people do it like this: -Includes -Variable Definitions -Function Definitions -Main Loop -Functions Can some one show me how to do it like that? It seems to be more organized.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster

#include "FooHeader.h"

static int SomeVariable = 1;

// forwad decleration of functions
void SomeFunction0();
float GetSomeStuff(float f);

int main()
{
SomeFunction0();
float value = GetSomeStuff(5.0f);

return 0;
}


void SomeFunction0()
{
printf("just junk");
}


float GetSomeStuff(float f)
{
return f * 10.0f;
}



Share this post


Link to post
Share on other sites

#include <header.h>

int global;

int function(int foo, int bar);

int main() {
...
}

int function(int foo, int bar) {
...
}




Or, if you want, you can leave off the names of the parameters in the declaration, like so:

int function(int, int);

EDIT: beaten. Oh well, I'll have to learn how to post faster :/

Share this post


Link to post
Share on other sites
The "advantage" to this is that you can place your main() "loop" before you actually implement the functions in the code... Otherwise you'd have to put main() at the bottom of your code ...

Note that declaring functions without actually implementing them is called prototyping :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!