int main(void)

Started by
13 comments, last by Cocalus 18 years, 8 months ago
do i have to call my main interger main? can i call it something else?
Advertisement
In C++ the valid function signatures for main() are:

int main();

and

int main(int argc, char * argv[]);
Quote:Original post by Avont29
do i have to call my main interger main? can i call it something else?
You don't have too, but there's few guarantees about what'll happen if you don't.
On most systems the worst that'll happen is that you get wierd exit codes from the application, except perhaps if you decide to return large structures in which case the application may even crash.

But.. Why would you want to return anything else?
you can call it whatever you want, as long as you return it with the correct type.

normally you could just stick with
int main(void){   //your program      return 0;}

if you are not doing anything too fancy, or even this:
void main(void){   //your program      //don't need to return}


EDIT: listen to the people above... I'm prolly wrong :D
but anyway i suggest you do the int one and return 0
-fuchiefck----------------------------------------------------------"Inside the world that you as a programmer or developer create, you are God" - Zerbst & Duvel
I believe it is incorrect to make main void. Even if you do not specifiy return 0 at the end of your code, the compiler does it automatically. ^_^
Quote:Original post by guyver23
Even if you do not specifiy return 0 at the end of your code, the compiler does it automatically. ^_^
It's true that C implicitly returns 0 from main if you don't return anything manually, C++ does have this somewhat strange convenience however.
Quote:Original post by guyver23
I believe it is incorrect to make main void. Even if you do not specifiy return 0 at the end of your code, the compiler does it automatically. ^_^


Its not standards compliant. The c++ standard (IIRC) says that main should return an int (specifically 0 for trouble free program run).
Quote:Original post by BosskIn Soviet Russia, you STFU WITH THOSE LAME JOKES!
Quote:Original post by SiCrane
In C++ the valid function signatures for main() are:

int main();

and

int main(int argc, char * argv[]);


yea what does int main(int argc, char * argv[]); do? says something about accepint command line arguemtns, but what does that mean?

and by the way , i was talking about something like this

changing

int main(void)

to

int Game_Int(void)
"main" is how the compiler knows where to start the program. If you want to put everything in something different, than from main, call a different function.
void GameLoop(){  /* code here */}int main( int argc, char ** argv ){  GameLoop();  return 0;}
william bubel
Quote:Original post by Avont29
Quote:Original post by SiCrane
In C++ the valid function signatures for main() are:

int main();

and

int main(int argc, char * argv[]);


yea what does int main(int argc, char * argv[]); do? says something about accepint command line arguemtns, but what does that mean?

and by the way , i was talking about something like this

changing

int main(void)

to

int Game_Int(void)



you can just do everything in your Game_Init() function and call it in main().

int main(void){   Game_Init();      return 0;}


but looking at it right now... you prolly want to do something like this:
(pseudo code)
int main(void){   Game_Init(); //init game variables etc      while(!GameEnded)   {       Game_Loop(); //main game looop   }   return 0;}

-fuchiefck----------------------------------------------------------"Inside the world that you as a programmer or developer create, you are God" - Zerbst & Duvel

This topic is closed to new replies.

Advertisement