Thread: quick question about exit() and functions

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    But he's breaking the standard (C89/90), He fails to return a value from main. While exit() is standard most compilers should still flag an error (when compiling in "strict" mode).

    You could do the following:

    Code:
    void MyExit(int code)
    {
        /* clean up vars here */
        exit(code);
    }
    
    void foo(void)
    {
        MyExit(0);
        return;
    }
    
    int main(void)
    {
        foo();
        return 0; /* never reached, just flag down the warnings */
    }
    But as MacGyver said, you should generally try and keep your exit()s grouped, as it can make your program hard to read (and workout where it ends). You can avoid it by designing your program well from the start, consider loops with boolean 'flags'.
    Last edited by zacs7; 05-16-2007 at 06:06 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 06-06-2008, 05:26 PM
  2. Odd memory leaks
    By VirtualAce in forum C++ Programming
    Replies: 11
    Last Post: 05-25-2006, 12:56 AM
  3. Replies: 1
    Last Post: 03-21-2006, 07:52 AM
  4. Couple of Q's.....
    By oobootsy1 in forum C++ Programming
    Replies: 18
    Last Post: 02-23-2004, 02:03 PM
  5. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 07:53 AM