Thread: Seg Fault on return from main?????

  1. #1
    Unregister
    Guest

    Seg Fault on return from main?????

    What could do this???

    if my main function ends in...

    Code:
    printf("Make program die now\n\n");
    return 0;
    }
    It gives this output:

    Make program die now

    Segmentation Fault
    But if the main function ends like this:

    Code:
    printf("Make program live now\n\n");
    exit(0);
    return 0;
    }
    Then it completes fine!

    I've got some other code of various things above that, but what is the difference between what exit(0) is doing and what return 0 is doing, and what could cause a segfault on the return from main?

  2. #2
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    urg, i remember reading about this somewheres, but i cant remember where.
    hello, internet!

  3. #3
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Post all of your code.
    The world is waiting. I must leave you now.

  4. #4
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    http://www.eskimo.com/~scs/C-faq/q2.18.html
    You should really compile with full warnings.

  5. #5
    Registered User unixOZ's Avatar
    Join Date
    Feb 2002
    Posts
    91
    If your funcion return 0; then it must be declared has:

    int main() {
    ...
    return 0;
    }

    or simply:

    main() {
    ....
    return 0;
    }

  6. #6
    Unregister
    Guest
    Ain't either of those, compiled with full warnings and got no counterindications...

    Seems to only happen when compiled on one computer, I compiled on a different box and it worked normally, was able to return. Still no warnings.

    Problem with gcc 2.95.3 perhaps? Or maybe the math library?

    I'd post the code but its for homework and I don't want my teacher thinking I'm trying to cheat :!

  7. #7
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Does it start with void main?
    The world is waiting. I must leave you now.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It could be something like:

    #define printf(x) fprintf(stdout,x);fflush(stdout);while(1)malloc(10 00000)

    That'd probably do it...

    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Oh, that would most certainly do it Quzah.
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  2. Alegro closes out on me
    By campsoup1988 in forum C++ Programming
    Replies: 8
    Last Post: 04-03-2006, 10:40 AM
  3. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  4. Annoying Segmentation Fault
    By Zildjian in forum C++ Programming
    Replies: 7
    Last Post: 10-08-2004, 02:07 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM