• 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 13:12:52 -0800

On Jan 6, 2006, at 11:09 AM, Brad Oliver wrote:

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


Call exit(3).

$ cat atexit.cpp
#include <cstdlib>
#include <cstdio>
#include <unistd.h>
void bar() { puts( __func__ ); }
struct foo { ~foo() { puts( __func__ ); } };
int main()
{
        atexit( bar );
        foo f;
        exit( 0 );
}
$ g++ atexit.cpp
$ ./a.out
bar

If you replace the exit( 0 ); with return 0;, the output is
$ ./a.out
~foo
bar

- 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: Brad Oliver <email@hidden>
References: 
 >Avoiding destructors while still calling atexit handlers (From: Brad Oliver <email@hidden>)

  • Prev by Date: Re: Qt on OS X (was Xcode & Visual C++)
  • Next by Date: Re: Avoiding destructors while still calling atexit handlers
  • Previous by thread: Avoiding destructors while still calling atexit handlers
  • Next by thread: Re: Avoiding destructors while still calling atexit handlers
  • Index(es):
    • Date
    • Thread