I've seen main functions with arguments before. ie:
int main(int something, int something_else)
What's passed to the main function? Is that for like.. variables passed via command line or something?
Standard main is:
int main(int argc, char *argv[])
argc is the number of commandline arguments, and argv is an array of the arguments,
- being the name of the program.
Cool, thanks!
Quote from: iago on March 27, 2003, 07:43 PM
Standard main is:
int main(int argc, char *argv[])
argc is the number of commandline arguments, and argv is an array of the arguments, - being the name of the program.
Don't forget:
int main(int argc, char *argv[], char *envp[])
I've not seen that one...what's the third param for? What would a second array of strings do there?
I would guess they are environmental variables, seeing as though it's called envp :)
Yes.
All three forms (0, 2, 3 parameters) are acceptable.
Quote from: Yoni on March 29, 2003, 04:33 AM
Yes.
All three forms (0, 2, 3 parameters) are acceptable.
void main() is
not acceptable, however, despite what Visual C++ might try to tell you.
envp is Windows specific, iirc. Use getenv() instead.
Quote from: Kp on March 29, 2003, 06:23 PM
envp is Windows specific, iirc. Use getenv() instead.
Ah, you're right. According to documentation, I've found, it's something most Windows and UNIX compilers implement, but not a standard feature.
int main(int argc, wchar_t *argv[]);
is this not supported?
Quote from: Etheran on April 08, 2003, 04:01 AM
int main(int argc, wchar_t *argv[]);
is this not supported?
If you want the argv argument to be a wide string, you'll have to rename
main to
wmain.
MSVC++ also allows the following:
int _tmain(int argc, TCHAR* argv[]);
Similarly with WinMain:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nShow);
// or
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int nShow);
// or
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR lpCmdLine, int nShow);
I've also seen void main(void) {...}
(This is with C btw) is that legal? And add preformated text tags, i dont like how [ code][/code ] creates a new line....
Quote from: MrRaza on April 08, 2003, 07:00 PM
I've also seen void main(void) {...}
(This is with C btw) is that legal? And add preformated text tags, i dont like how [ code][/code ] creates a new line....
No, that's not standard C (or C++). http://www.eskimo.com/~scs/readings/voidmain.960823.html
void main is simply
wrong.
Well, i guess my C++ book is wrong, but hey atleast it has some good AI information in it..