atexit not running?

This is a discussion on atexit not running? within the C++ Programming forums, part of the General Programming Boards category; I'm trying to set up a shutdown function to delete a scene tree in glut. I put the atexit call ...

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    atexit not running?

    I'm trying to set up a shutdown function to delete a scene tree in glut. I put the atexit call at the beginning of main:
    Code:
    atexit(shutDown);
    and the function itself looks like:
    Code:
    void shutDown() {
    	printf("shutting down...\n");
    	delete root;
    }
    This seems like it should run to me, but I don't see anything when the program ends. What am I doing wrong?
    Illusion and reality become impartiality and confidence.

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    what's going on? is the program just 'dissapearing'? if so, you may need to put something there to stop execution (like an input statement)

    you may need to stop the program with the exit() function.

    I would probably avoid using atexit though - it makes for spagetti code. if you need functionality like that put it in a class (if you're using C++)
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,854
    Where I'm sitting, atexit() returns a value - what does it return for you?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    major_small:
    The program is giving the "press any key etc etc" thing before closing down the window, so I assume I'm getting everything that's been sent to stdout. I have to use atexit because I'm using glut to make this program, which uses a callback system and ends execution on its own at some undetermined point.

    salem:
    atexit returns 0, msdn says that's good times.
    Illusion and reality become impartiality and confidence.

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    >> The program is giving the "press any key etc etc" thing before closing down the window

    Then, the function given to atexit really ought to be called after this... Perhaps a more reliable test would be to print something to a file in your shutDown function (so that it persists once the window closes). Or, run your program from the command line.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 12-09-2008, 11:09 AM
  2. Check number of times a process is running
    By linuxwolf in forum Windows Programming
    Replies: 6
    Last Post: 10-17-2008, 12:08 PM
  3. Monitor a running instance of MS Word
    By BobS0327 in forum C# Programming
    Replies: 0
    Last Post: 07-18-2008, 01:40 PM
  4. Replies: 2
    Last Post: 05-12-2006, 11:28 AM
  5. multithreading question
    By ichijoji in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2005, 11:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21