Jump to content
  • Advertisement
Sign in to follow this  
Avont29

int main(void)

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

Advertisement
In C++ the valid function signatures for main() are:

int main();

and

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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. ^_^

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
"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;
}

Share this post


Link to post
Share on other sites
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;
}

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!