Thread: return from main

  1. #1
    Unregistered
    Guest

    return from main

    A return value of 0 from main signals all is fine any other value indicates some sort of error but where do these returns from main go to I know they go to the operating system but where and why because my program/compiler will indicate any errors if there are any.

    thanks for the help.
    learner wanting to be a master.

  2. #2
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    Obtaining this value depends on the operating system you are using. In POSIX systems such as Linux, this is shell dependant as well. Which OS are you using? If you are using *nix, which shell?

    You might also think about posting your question in the DOS/Windows/Linux message board if you are using one of those operating systems.
    Last edited by Deckard; 01-11-2002 at 01:47 PM.
    Jason Deckard

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793

    Re: return from main

    Originally posted by Unregistered
    A return value of 0 from main signals all is fine any other value indicates some sort of error but where do these returns from main go to I know they go to the operating system but where and why because my program/compiler will indicate any errors if there are any.

    thanks for the help.
    learner wanting to be a master.
    The return used to be good for .BAT files as you could test the success of a command and branch the rest of the script accrodingly............

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    The program you run is a childprocess in an environment, in some cases this environment is the OS, but in other cases it can be some other program. The return-value of main informs the environment of how the program has finished.

    Note that main is just a function, just as for example fopen is. When using fopen you check the result, if it is NULL, then you know that something has gone wrong. And with main it's the same case. If it sends back FALSE, than the environment knows that something has gone wrong.

    FALSE can be 1 or 0 or even some other value, since main returns an int. You should check the documentation of the environment to find out how it interprets the return value.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to combine these working parts??
    By transgalactic2 in forum C Programming
    Replies: 0
    Last Post: 02-01-2009, 08:19 AM
  2. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 10:00 PM
  3. DirectInput help
    By Muphin in forum Game Programming
    Replies: 2
    Last Post: 09-10-2005, 11:52 AM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 01:54 AM