Sign in to follow this  

A little syntax help...

This topic is 4854 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
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

This topic is 4854 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this