A little syntax help...

Started by
4 comments, last by Imperio59 19 years, 8 months ago
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.
---"What? What is it? Is it the monkey in the pants? It's the monkey in the pants, isn't it. Don't give me that look."
Advertisement
yours looks better, but it doesnt matter all that much
#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 :/
Thanks!
---"What? What is it? Is it the monkey in the pants? It's the monkey in the pants, isn't it. Don't give me that look."
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 :)
Imperio59 - C++ Programmer

This topic is closed to new replies.

Advertisement