A little syntax help...
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.
#include "FooHeader.h"static int SomeVariable = 1;// forwad decleration of functionsvoid 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;}
#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 :/
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 :)
Note that declaring functions without actually implementing them is called prototyping :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement