Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenstterm-test.cc
Go to the documentation of this file.
00001 /* 00002 * The conversation with Matti Rintala on STLport forum 2005-08-24: 00003 * 00004 * Do you mean ISO/IEC 14882 3.6.3 [basic.start.term]? 00005 * 00006 * Yes. "Destructors (12.4) for initialized objects of static storage duration 00007 * (declared at block scope or at namespace scope) are called as a result 00008 * of returning from main and as a result of calling exit (18.3). These objects 00009 * are destroyed in the reverse order of the completion of their constructor 00010 * or of the completion of their dynamic initialization." 00011 * 00012 * I found a confirmation on the web that gcc may not strictly conform 00013 * to this behaviour in certains cases unless -fuse-cxa-atexit is used. 00014 * 00015 * Test below give (without -fuse-cxa-atexit) 00016 00017 Init::Init() 00018 Init::use_it 00019 It ctor done <-- 0 00020 Init::use_it done 00021 Init ctor done <-- 1 00022 Init2 ctor done <-- 2 00023 It dtor done <-- 0 00024 Init2 dtor done <-- 2 00025 Init dtor done <-- 1 00026 00027 00028 * but should: 00029 00030 Init::Init() 00031 Init::use_it 00032 It ctor done <-- 0 00033 Init::use_it done 00034 Init ctor done <-- 1 00035 Init2 ctor done <-- 2 00036 Init2 dtor done <-- 2 00037 Init dtor done <-- 1 00038 It dtor done <-- 0 00039 00040 00041 */ 00042 #include <stdio.h> 00043 00044 using namespace std; 00045 00046 class Init 00047 { 00048 public: 00049 Init(); 00050 ~Init(); 00051 00052 static void use_it(); 00053 }; 00054 00055 class Init2 00056 { 00057 public: 00058 Init2(); 00059 ~Init2(); 00060 00061 }; 00062 00063 static Init init; 00064 static Init2 init2; 00065 00066 class It 00067 { 00068 public: 00069 It(); 00070 ~It(); 00071 }; 00072 00073 Init::Init() 00074 { 00075 printf( "Init::Init()\n" ); 00076 use_it(); 00077 printf( "Init ctor done\n" ); 00078 } 00079 00080 Init::~Init() 00081 { 00082 printf( "Init dtor done\n" ); 00083 } 00084 00085 void Init::use_it() 00086 { 00087 printf( "Init::use_it\n" ); 00088 00089 static It it; 00090 00091 printf( "Init::use_it done\n" ); 00092 } 00093 00094 Init2::Init2() 00095 { 00096 printf( "Init2 ctor done\n" ); 00097 } 00098 00099 Init2::~Init2() 00100 { 00101 printf( "Init2 dtor done\n" ); 00102 } 00103 00104 It::It() 00105 { 00106 printf( "It ctor done\n" ); 00107 } 00108 00109 It::~It() 00110 { 00111 printf( "It dtor done\n" ); 00112 } 00113 00114 int main() 00115 { 00116 return 0; 00117 } Generated on Sat May 26 2012 04:34:04 for ReactOS by
1.7.6.1
|