title: Difference between .dtors and atexit() in C++
body: <p>What is the difference between functions in <code>.dtors</code> and functions called using <code>atexit()</code>?</p>
  
  <p>As I understand, functions marked with the <code>((destructor))</code> attribute are located in the <code>.dtors</code> segment, and called after exit. Likewise, functions added using <code>atexit(fctName)</code> are placed in an array and also called after a normal execution end.</p>
  
  <p>So why does C++ provide two distinct mechanisms here? Are there distinct things that can be done only with one? Can I only add a function dynamically using <code>atexit()</code>?  </p>
  
  <p>Also which are called first, functions in <code>.dtors</code> or functions added using <code>atexit()</code>?</p>