Topic: atexit and/or objects with global storage duration


Author: dsp@bdal.de (=?ISO-8859-1?Q?=22Daniel_Kr=FCgler_=28nee_Spangenberg=29=22?=)
Date: Fri, 16 Apr 2004 15:26:35 +0000 (UTC)
Raw View
Ben Hutchings schrieb:

>"Daniel Kr=FCgler (nee Spangenberg)" wrote:
> =20
>
>>Hello community,
>>
>>yesterday night I stumbled about a problem, for which I could not
>>find an answer in the current C++ standard (2003).
>>   =20
>>
>
>See 18.3/8.  It's not easy to read, but it does cover this situation.
>The 1998 standard did not (see
><http://std.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#3>).
>
><snip>=20
>
You are absolutely right, obviously I was to sleepy to recognize the=20
complete meaning of these
words;-). Funnily the original descriptive part of defect #3 claims to=20
conclude that my example
should lead to undefined behaviour, although the actual proposed (and=20
realized) solution does not
follow this recommandation (I think the solution is quite natural and=20
seems to reflect current
practice, although I did not expect that).

>>Is this program wellformed or does it lead to undefined behaviour?
>>   =20
>>
><snip>
>
>You are confusing two different kinds of error.  If a program is not
>well-formed, this error can and must be detected and reported at
>compile time.  "Undefined behaviour" can only occur in situations
>which the standard does not require implementors to detect.
> =20
>
Right again - abuse of well defined concepts lead to the longest and=20
passionate threads in usenet
and usually I am more careful in the choice of my words.

Greetings from Bremen,

Daniel Kr=FCgler


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: dsp@bdal.de (=?ISO-8859-1?Q?=22Daniel_Kr=FCgler_=28nee_Spangenberg=29=22?=)
Date: Thu, 15 Apr 2004 17:10:10 +0000 (UTC)
Raw View
Hello community,

yesterday night I stumbled about a problem, for which I could not find=20
an answer in the
current C++ standard (2003). Please consider the following program:

//-------------------------------------------
#include <iostream>
#include <ostream>

struct A{
  ~A() {
    std::cout << "Bye-bye world" << std::endl;
  }
};

struct B {
  ~B()  {
     static A a;
   }
};=20

B b;

int main(){}
//-------------------------------------------

Is this program wellformed or does it lead to undefined behaviour? To=20
make my
point somewhat more clear, please consider the following alternative=20
program, which
should (to my opinion) have the same observable effect (at least if I=20
interpret correctly
the usual answer of standardists considering the equivalent behaviour of=20
functions
registered with atexit and the denstruction sequence of objects with=20
global storage
duration):

//-------------------------------------------
#include <iostream>
#include <ostream>
#include <cstdlib>

void a() {
    std::cout << ""Bye-bye world" << std::endl;
};

void b() {
  std::atexit(a);
};=20

int main(){
  std::atexit(b);
}
//-------------------------------------------

My basic question is, whether the call of atexit (or its equivalent)=20
**following** the call of exit
(which implicitely happens after leaving the main function) is a=20
wellformed process. I could not find
anything in the standard, what contradicts to that assumption, but am I=20
right?

Thanks for your help,

Daniel Kr=FCgler




---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: do-not-spam-benh@bwsint.com (Ben Hutchings)
Date: Thu, 15 Apr 2004 19:59:59 +0000 (UTC)
Raw View
"Daniel Kr=FCgler (nee Spangenberg)" wrote:
> Hello community,
>=20
> yesterday night I stumbled about a problem, for which I could not
> find an answer in the current C++ standard (2003).

See 18.3/8.  It's not easy to read, but it does cover this situation.
The 1998 standard did not (see
<http://std.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#3>).

<snip>=20
> Is this program wellformed or does it lead to undefined behaviour?
<snip>

You are confusing two different kinds of error.  If a program is not
well-formed, this error can and must be detected and reported at
compile time.  "Undefined behaviour" can only occur in situations
which the standard does not require implementors to detect.

Anyway, I believe your program is well-formed and does not have
undefined behaviour.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]