Exit with Return

This is a discussion on Exit with Return within the Linux Programming forums, part of the Platform Specific Boards category; Hi I am looking for a “termination” routine that executes finalization/cleanup code, registered via atexit() and global/static object deconstructors, except ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    162

    Question Exit with Return

    Hi

    I am looking for a “termination” routine that executes finalization/cleanup code, registered via atexit() and global/static object deconstructors, except it doesn’t end the process. Instead returns to the caller (which in turn should fully exit the process) or performs an assignable callback (and then terminates).

    So far I have only encountered two such functions: _cexit() for windows and _exithandle() for solaris (which I am not quite sure performs as expected). But I also seek such implementations for Linux, any ideas? “Macros Controlling Initialization Routines” in GCC might help if I could make sense of them.

    Any help is appreciated.
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    > Instead returns to the caller
    What does this mean? Returns to main?

    If you want to get back to main from anywhere, then use setjmp() and longjmp().

    But this won't execute anything registered with atexit(), and won't execute any global/static object deconstructors either. You need to specifically return from main or call exit() for these things to happen.

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    162
    > Instead returns to the caller
    What does this mean? Returns to main?
    No not main but the function the "terminating" routine was called from. Instead ending the program and never returing, such as the case with exit().

    To further clarify:
    I am looking for a function that performs cleanup as exit(), but doesn’t terminate the program, and instead returns or does some sort of callback.
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    > No not main but the function the "terminating" routine was called from.
    You mean like every other function returns to the place it was called from.

    Or do you mean to the place where the terminating routine was registered from?

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    162
    Quote Originally Posted by Salem
    >You mean like every other function returns to the place it was called from.
    Yes, precisely.
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  6. #6
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235
    A I read this, you're looking for a library function that you can call that will close all open file descriptors, call the chain of registered exit handlers, and do all the other cleanup that exit() does, then return to the caller so that some other exit processing might be done.

    There is no standard entry point for this. It is compiler run-time library dependent, and may even be different between operating systems using the same compiler.

    If you have access to glibc (or the C runtime support library for your compiler, whatever it is) sources, you might want to look at the source for the function _exit().
    Insert obnoxious but pithy remark here

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    I've no idea what he wants. Calling the global destructors before main() exits makes no sense - what if you then use a global object on you way back to main?

    Perhaps a description of the problem, rather than how to implement an imagined solution would help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Alegro closes out on me
    By campsoup1988 in forum C++ Programming
    Replies: 8
    Last Post: 04-03-2006, 10:40 AM
  3. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 06:57 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM

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