author | sl@SLION-WIN7.fritz.box |
Fri, 15 Jun 2012 03:10:57 +0200 | |
changeset 0 | bde4ae8d615e |
permissions | -rw-r--r-- |
1 /*
2 * The conversation with Matti Rintala on STLport forum 2005-08-24:
3 *
4 * Do you mean ISO/IEC 14882 3.6.3 [basic.start.term]?
5 *
6 * Yes. "Destructors (12.4) for initialized objects of static storage duration
7 * (declared at block scope or at namespace scope) are called as a result
8 * of returning from main and as a result of calling exit (18.3). These objects
9 * are destroyed in the reverse order of the completion of their constructor
10 * or of the completion of their dynamic initialization."
11 *
12 * I found a confirmation on the web that gcc may not strictly conform
13 * to this behaviour in certains cases unless -fuse-cxa-atexit is used.
14 *
15 * Test below give (without -fuse-cxa-atexit)
17 Init::Init()
18 Init::use_it
19 It ctor done <-- 0
20 Init::use_it done
21 Init ctor done <-- 1
22 Init2 ctor done <-- 2
23 It dtor done <-- 0
24 Init2 dtor done <-- 2
25 Init dtor done <-- 1
28 * but should:
30 Init::Init()
31 Init::use_it
32 It ctor done <-- 0
33 Init::use_it done
34 Init ctor done <-- 1
35 Init2 ctor done <-- 2
36 Init2 dtor done <-- 2
37 Init dtor done <-- 1
38 It dtor done <-- 0
41 */
42 #include <stdio.h>
44 using namespace std;
46 class Init
47 {
48 public:
49 Init();
50 ~Init();
52 static void use_it();
53 };
55 class Init2
56 {
57 public:
58 Init2();
59 ~Init2();
61 };
63 static Init init;
64 static Init2 init2;
66 class It
67 {
68 public:
69 It();
70 ~It();
71 };
73 Init::Init()
74 {
75 printf( "Init::Init()\n" );
76 use_it();
77 printf( "Init ctor done\n" );
78 }
80 Init::~Init()
81 {
82 printf( "Init dtor done\n" );
83 }
85 void Init::use_it()
86 {
87 printf( "Init::use_it\n" );
89 static It it;
91 printf( "Init::use_it done\n" );
92 }
94 Init2::Init2()
95 {
96 printf( "Init2 ctor done\n" );
97 }
99 Init2::~Init2()
100 {
101 printf( "Init2 dtor done\n" );
102 }
104 It::It()
105 {
106 printf( "It ctor done\n" );
107 }
109 It::~It()
110 {
111 printf( "It dtor done\n" );
112 }
114 int main()
115 {
116 return 0;
117 }