delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/05/11/07:01:19

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <48781a66050511040119156dc9@mail.gmail.com>
Date: Wed, 11 May 2005 07:01:07 -0400
From: "William M. (Mike) Miller" <william DOT m DOT miller AT gmail DOT com>
Reply-To: "William M. (Mike) Miller" <william DOT m DOT miller AT gmail DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Static destructors not running
In-Reply-To: <20050510160904.GF15665@trixie.casa.cgf.cx>
Mime-Version: 1.0
References: <48781a66050509154660edcc78 AT mail DOT gmail DOT com> <SERRANONlJbSorxTjtR000002ab AT SERRANO DOT CAM DOT ARTIMI DOT COM> <48781a6605051006066aa9b036 AT mail DOT gmail DOT com> <20050510153512 DOT GZ15665 AT trixie DOT casa DOT cgf DOT cx> <48781a66050510085450bd1339 AT mail DOT gmail DOT com> <20050510160904 DOT GF15665 AT trixie DOT casa DOT cgf DOT cx>
X-IsSubscribed: yes
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id j4BB1HXb025276

On 5/10/05, Christopher Faylor <cgf-no-personal-reply-please AT cygwin DOT com> wrote:
> Previous to 1.5.16, static destructors were always called via a
> gcc "atexit" mechanism.  This meant that there were scenarios where
> destructors would not be called at all so I made cygwin's exit call
> the destructors explicitly.   I just forgot to make cygwin do the right
> thing when returning from main rather than exiting.  This will be
> fixed in the next snapshot.

There's one more glitch in this.  The order of destruction of static
objects should be the inverse of their order of construction,
regardless of whether they are global or local.  In 1.5.16 and the
latest snapshot, global static objects are destroyed before local
static objects, regardless of the order of construction.  Here's a
demo program:

    #include <stdio.h>
    struct A {
      int i;
      A(int p) : i(p) { printf("A::A(%d)\n", i); }
      ~A() { printf("A::~A for %d\n", i); }
    };
    A a(1);
    void f() {
      static A a(3);
    }
    main () {
      static A a(2);
      printf("main\n");
      f();
    }

In the new Cygwin versions, the output is:

    A::A(1)
    A::A(2)
    main
    A::A(3)
    A::~A for 1
    A::~A for 3
    A::~A for 2

The destructors should print 3, 2, 1 instead of 1, 3, 2.

-- 
William M. (Mike) Miller
william DOT m DOT miller AT gmail DOT com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019