int main(void)
In C++ the valid function signatures for main() are:
int main();
and
int main(int argc, char * argv[]);
int main();
and
int main(int argc, char * argv[]);
Quote:Original post by Avont29You don't have too, but there's few guarantees about what'll happen if you don't.
do i have to call my main interger main? can i call it something else?
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
if you are not doing anything too fancy, or even this:
EDIT: listen to the people above... I'm prolly wrong :D
but anyway i suggest you do the int one and return 0
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
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 guyver23It's true that C implicitly returns 0 from main if you don't return anything manually, C++ does have this somewhat strange convenience however.
Even if you do not specifiy return 0 at the end of your code, the compiler does it automatically. ^_^
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 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;}
Quote:Original post by Avont29Quote: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;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement