Sign in to follow this  

int main()

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

Hi, whenever you read a newb tutorial or anything, everyone always says put
int main()
{
//...
return 0;
}
I'm just curious though..Why? void main() does the same thing, and why do you always return 0? can't you return 17, or maybe even 16? Is there even a way to return the value? Just questions i've wondered about for a long time, thanks.

Share this post


Link to post
Share on other sites
kag,

Its part of the C++ coding standard to have main() return an integer, rather than void, though its still possible to have main return void on many compilers.

The reason for this is that the value returned from your application is treated as an error code. The reason most people return 0 at the end of their application is that they're certifying that the application has closed "without error."

It is entirely possible to return 17 or even -1000.

You can capture the return value using the PlatformSDK I believe, or using the COMMAND shell.

EDIT: heh, too slow.

Share this post


Link to post
Share on other sites
Thank you two for your answers..

Does anyone perhaps know using the platform SDK how to pick up that return value?

What I kinda wanted to do was use AppA to run AppB, but I want to know when the AppB exits..and without a error..my code I would want to look like this

(we'll pretend that AppB is an uploader that uploads a directory of files, and takes the directory to upload as a command line argument)


int main()
{
vector<string> DirectoriesToUpload;

int error = 0;
do
{
int error = AppB.Start(DirectoriesToUpload[i].c_str());
} while ((error == 0) && (AllDirectoriesArn'tUploadedYet) );

return 17; // ;-)
}


Is it possible to do something like that?
Or is that just stupid?

Share this post


Link to post
Share on other sites
It's quite possible, look up the system() function. Here's an example:


#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
int result = 0;
cout << "Loading program B... "
result = system("AppB.exe");
cout << result << endl;
return 0;
}




That should work, but I'm not so sure the the result variable will work, although system() does return an int, so it might.

Share this post


Link to post
Share on other sites

This topic is 4559 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this