Thread: Significance of exit()

  1. #1
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300

    Significance of exit()

    This is kind of unlikely, but I thought I'd ask and see.

    I just started fooling around with SDL*. I've used openGL with glut before, so all I've done so far is get my OGL stuff to work with that instead. UNFORTUNATELY, I've run into this issue where when the program exits, it sometimes causes X to crash (the backtrace begins and ends in /usr/lib64/xorg/modules/extensions/libglx.so). This never happened with glut, BTW, and it does not happen with non-GL SDL stuff.

    Now, this just happened this afternoon, so I have not really repeatedly tested this much, but it seems to me that by using stdlib.h and "exit()" (in main, instead of just return) that the chances of the fault occuring are much reduced. I did this because the SDL doc "example 2.8" which demos how to use OGL in SDL uses exit (because there is a seperate clean-up function) and it seemed to cause the fault less, so I went thru looking at how that code differs from mine, et. al.

    Of course, the fact that it doesn't happen all the time means my statistical inferences here could be totally based on coincidence. Also, this is obviously a problem in libglx, and not in my program BUT is there any possible rational connection between the use of exit() instead of a main() return and the apparent decrease in X faults?


    *I decided I wanna make a video game...like a FPS 3D version of "break out" or "win brick", ie, you are the paddle, you can move in x and y, the bricks are layered in all THREE dimensions, and you can angle the (square) paddle around the x and y axis -- anyone know if this has been done before? I thought a great networked version would be to start from 2 opposite sides of the brick-mass (maybe even all 6!), multiple balls (one per player, but they can end up anywhere), lost balls are replaced but you loose points for loosing them, and the goal is to destroy the most bricks before the whole mass is gone.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    atexit perhaps?


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

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by quzah View Post
    atexit perhaps?
    No, there's no atexit() used. I guess my question basically is, is there anything at all different about using exit instead of return (in main).
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Check the assembler generated.
    Mainframe assembler programmer by trade. C coder when I can.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Well, surprise surprise this was a coding error -- perhaps. It only happens if I set the video mode past 640x480. This was not an issue with glut! But that is a whole separate bunch o' questions.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Huh, you mean random segfaults mean you messed up?! Who saw that coming?


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

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Sort of a more happy conclusion than finding out your system libraries are screwy and that your dreams of creating a 3D FPS multiplayer block (should that be cube?) breaker game are dashed unless you want to buy some new hardware and/or reinstall/upgrade/change the OS.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    Quote Originally Posted by MK27 View Post
    No, there's no atexit() used. I guess my question basically is, is there anything at all different about using exit instead of return (in main).
    The original problem has been solved, but in case anybody's interested, no, there's no difference between returning from main() and calling exit, except for two cases:

    1. main() is defined as not returning an int (only C99, and then it's still implementation defined because a portable program must have main() return an int).
    2. main() has been called recursively and one of these recursive calls returns from main()—this does what is expected; only a return from the “original” main() is equivalent to exit().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Chat Program Help?
    By Paul22000 in forum Networking/Device Communication
    Replies: 9
    Last Post: 02-10-2009, 12:35 AM
  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. Dynamic array of pointers
    By csisz3r in forum C Programming
    Replies: 8
    Last Post: 09-25-2005, 02:06 PM
  5. exit() ?
    By smd in forum C++ Programming
    Replies: 4
    Last Post: 06-26-2002, 04:31 PM

Tags for this Thread