• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Avoiding destructors while still calling atexit handlers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Avoiding destructors while still calling atexit handlers


  • Subject: Re: Avoiding destructors while still calling atexit handlers
  • From: Steve Checkoway <email@hidden>
  • Date: Fri, 6 Jan 2006 15:15:57 -0800


On Jan 6, 2006, at 2:45 PM, Brad Oliver wrote:

On Jan 6, 2006, at 2:12 PM, Steve Checkoway wrote:

What's the cleanest way to avoid calling the C++ destructor chain while still calling routines registered with atexit()?

Call exit(3).

Thanks, now I have a bonus follow-up question. ;-)

What's the cleanest way to avoid calling C++ destructors (including those for static objects) while still calling routines registered with atexit()?

Okay, this one is tricker. The most simply way to simply avoid the dtors is to have something like:


void last_handler() { _Exit(0); }

and then set it as the very first atexit handler.

However, this may not flush buffers, close streams or unlink temporary files created with tmpfile. Calling _exit(2) will not do so. The man page for _Exit(3), however, says that it "may or may not perform the other actions listed."

I'm not sure why you want to avoid the dtors being called but it might be simply easier to have a global flag that you set when you are about to exit and do not want the dtors to do anything. Then, in the dtor, just check if the flag is set or not before doing whatever it is that is normally done there.

- Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Avoiding destructors while still calling atexit handlers
      • From: Brian Onn <email@hidden>
    • Re: Avoiding destructors while still calling atexit handlers
      • From: Steve Checkoway <email@hidden>
References: 
 >Avoiding destructors while still calling atexit handlers (From: Brad Oliver <email@hidden>)
 >Re: Avoiding destructors while still calling atexit handlers (From: Steve Checkoway <email@hidden>)
 >Re: Avoiding destructors while still calling atexit handlers (From: Brad Oliver <email@hidden>)

  • Prev by Date: Re: Avoiding destructors while still calling atexit handlers
  • Next by Date: Re: Avoiding destructors while still calling atexit handlers
  • Previous by thread: Re: Avoiding destructors while still calling atexit handlers
  • Next by thread: Re: Avoiding destructors while still calling atexit handlers
  • Index(es):
    • Date
    • Thread