View Single Post
  #2 (permalink)  
Old July 17th, 2003, 01:41 PM
johan_yo johan_yo is offline
Registered User
 
Join Date: Jul 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm not an expert, so my answer might be wrong.

There is NO standard (set) prototype for main() function. When your exe runs, it will start with function with name main, doesn't matter the return type or arguments. If you have more than 1 main(), your compiler might warn/yell at you.

The most complete one is:
int main(int argc, char* argv[], char *envp[]);
   where: argc is how many arguments pass to exe (including the exe filename)
          argv is each arguments pass to exe
          envp is pointer to array of env string (specific to Windows)

NOTE: main starts and ends the program. You can use the return value to check the end status of your program. Remember that you can start another exe from another exe, so you can check how the called exe ends (eg returnVal<0 means fatal error, returnVal=0 means end successfully, returnVal=1 means end with minor error). Don't ask me the coding, I don't know, never use it before.


Since I was first trained on UNIX, I use:
int main(int argc, char* argv[]);
eg. C:> mytestProg.exe foo bar
   argc will be 3
   argv[0] will be "mytestProg.exe"
   argv[1] will be "foo"
   argv[2] will be "bar"

cheers,
&nbsp;&nbsp;Johan
Reply With Quote