Does __attribute__ ((destructor)) run on crash?

This is a discussion on Does __attribute__ ((destructor)) run on crash? within the C++ Programming forums, part of the General Programming Boards category; Will gcc's deconstructor still run if the program crashes (due to a segfault or whatever else), or only on a ...

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    12

    Does __attribute__ ((destructor)) run on crash?

    Will gcc's deconstructor still run if the program crashes (due to a segfault or whatever else), or only on a successful exit or end of main?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    All bets are off as soon as your program does anything not covered by the standard - such as accessing non existent memory causing segfaults.

    Plus the manual page only mentions normal exits.
    Quote Originally Posted by gcc manual
    The constructor attribute causes the function to be called automatically before execution enters main (). Similarly, the destructor attribute causes the function to be called automatically after main () has completed or exit () has been called. Functions with these attributes are useful for initializing data that will be used implicitly during the execution of the program.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's The Deal With __attribute and __attribute__?
    By Shokwav in forum C++ Programming
    Replies: 1
    Last Post: 05-23-2011, 10:35 PM
  2. Replies: 9
    Last Post: 07-23-2010, 06:31 PM
  3. Destructor crash
    By Abbygail in forum C++ Programming
    Replies: 1
    Last Post: 05-25-2009, 07:31 PM
  4. Crash in destructor
    By vaibhavs17 in forum C++ Programming
    Replies: 4
    Last Post: 04-06-2009, 11:10 AM
  5. Replies: 2
    Last Post: 04-26-2008, 04:43 AM

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