I didn't even know you can have parameters in the main function so when would you want to have parameters in your main function? Also can someone explain why these libraries' main functions have parameters when they are never used?
It is the commandline arguments passed to the progam. The first int argument is the number of arguments and the second string array is the arguments themselves.
SDL and OpenGL does not have their own main function, you are using the regular plain old main function and calling SDL or OpenGL functions from it.jjj
And it's not just SDL and OpenGL that have them. Make a blank C/++ project and add the same parameters (and try to print the first argument). You should technically always have them.
xx6heartless6xx wrote:Okay so from now on I should always have them in every program? And how come my C++ book does not make me put it?
They probably want to keep their basic examples as uncluttered as possible, so they can explain the very basics without having people thinking "What are those words and characters between the parenthesis for?".
Since Falco says that you should use them, i guess they are part of the specification, but most compilers let you omit them, since they aren't always used. I'm not quite sure about that though.
It is not required to have main() parameters in any program other than SDL on windows, unless you are using command line arguments. Why SDL on windows? Because on windows, a graphical program doesn't have a main, it has a WinMain. So what does SDL do?
#define main SDL_main
extern C_LINKAGE int SDL_main(int argc, char *argv[]);
It pre-declares main so that it can run it in its WinMain. Because it's already predeclared, main() now can't work unless it has arguments. A hack? Definitely, but it works.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.