<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>CRT Initialization</title><link>http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx</link><description>Hi, I’m George Mileka and I work on the Visual C++ libraries team. My team owns the CRT, ATL, MFC and STL… One subject I have always been interested in is the startup code and initialization. The subject got even more challenging as we started supporting</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: CRT Initialization</title><link>http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx#850271</link><pubDate>Fri, 20 Oct 2006 22:55:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:850271</guid><dc:creator>Tompa</dc:creator><description>&lt;p&gt;Great - this is just the kind of post that I like to read! More of this 'under the hood' stuff please!&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;/Tompa&lt;/p&gt;
</description></item><item><title>re: CRT Initialization</title><link>http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx#853179</link><pubDate>Sat, 21 Oct 2006 21:06:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:853179</guid><dc:creator>Emmanuel</dc:creator><description>&lt;p&gt;Great - it is so amusing to really know something about this 'under the hood' kind of stuff. With Tompa, I would voice that we get something to read of such stuff (behind the scenes subjects).&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Emmanuel&lt;/p&gt;
</description></item><item><title>re: CRT Initialization</title><link>http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx#933056</link><pubDate>Thu, 02 Nov 2006 19:14:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:933056</guid><dc:creator>cpizano</dc:creator><description>&lt;p&gt;it would be nice to talk about what happens if an exception is thrown at the initializers&lt;/p&gt;
</description></item><item><title>re: CRT Initialization</title><link>http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx#1014623</link><pubDate>Tue, 07 Nov 2006 14:23:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1014623</guid><dc:creator>Bhavesh</dc:creator><description>&lt;p&gt;Hi,I am still not be able to understand what you talked.But i am veri interested and also require some help on CRT Startup code.&lt;/p&gt;
</description></item><item><title>re: CRT Initialization</title><link>http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx#1044076</link><pubDate>Thu, 09 Nov 2006 17:18:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1044076</guid><dc:creator>Vipul Garg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I don't have basic concepts of CRT and i m very much interested to have some reference material on that.&lt;/p&gt;
</description></item><item><title>re: CRT Initialization</title><link>http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx#1055190</link><pubDate>Fri, 10 Nov 2006 23:24:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1055190</guid><dc:creator>grmileka</dc:creator><description>&lt;p&gt;Thanks for the positive feedback!&lt;/p&gt;
&lt;p&gt;cpizano,&lt;/p&gt;
&lt;p&gt;Throwing an exception during the execution of initializers is indeed very important to understand... I'll see if I have some handy material on that subject...&lt;/p&gt;
</description></item><item><title>re: CRT Initialization</title><link>http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx#1055195</link><pubDate>Fri, 10 Nov 2006 23:25:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1055195</guid><dc:creator>grmileka</dc:creator><description>&lt;p&gt;Forgot to sign my last entry :)&lt;/p&gt;
&lt;p&gt;George Mileka&lt;/p&gt;
&lt;p&gt;Visual C++ Libraries Team&lt;/p&gt;
</description></item><item><title>re: CRT Initialization</title><link>http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx#1055237</link><pubDate>Fri, 10 Nov 2006 23:42:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1055237</guid><dc:creator>George Mileka</dc:creator><description>&lt;p&gt;Bhavesh and Vipul,&lt;/p&gt;
&lt;p&gt;Unfortunately, I'm not aware of any books that discuss the internal implementation of the Microsoft CRT.&lt;/p&gt;
&lt;p&gt;However, one very good book about CRT is:&lt;/p&gt;
&lt;p&gt;The Standard C Library - by P. J. Plauger &lt;/p&gt;
&lt;p&gt;George Mileka&lt;/p&gt;
&lt;p&gt;Visual C++ Libraries Team&lt;/p&gt;
</description></item><item><title>My homepage</title><link>http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx#1122568</link><pubDate>Wed, 22 Nov 2006 17:58:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1122568</guid><dc:creator>Troy</dc:creator><description>&lt;p&gt;Great work!&lt;/p&gt;
&lt;p&gt;[url=&lt;a rel="nofollow" target="_new" href="http://wskyqzfn.com/javv/yeqt.html"&gt;http://wskyqzfn.com/javv/yeqt.html&lt;/a&gt;]My homepage[/url] | [url=&lt;a rel="nofollow" target="_new" href="http://ysleefsp.com/pozl/wgzx.html"&gt;http://ysleefsp.com/pozl/wgzx.html&lt;/a&gt;]Cool site[/url]&lt;/p&gt;
</description></item><item><title>Converting to MSBuild</title><link>http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx#1226274</link><pubDate>Thu, 07 Dec 2006 02:04:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1226274</guid><dc:creator>Visual C++ Team Blog</dc:creator><description>&lt;p&gt;Hi, My name is Andreea Isac and I’ve been a member of the Visual C++ Libraries team for one year and&lt;/p&gt;
</description></item><item><title>re: CRT Initialization</title><link>http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx#1229434</link><pubDate>Thu, 07 Dec 2006 07:13:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1229434</guid><dc:creator>Albert Kennis</dc:creator><description>&lt;p&gt;One question and one request please.&lt;/p&gt;
&lt;p&gt;Let's say that we want to ensure the availabilty of some resource before main gets called. &amp;nbsp;For example:&lt;/p&gt;
&lt;p&gt;/* globals */&lt;/p&gt;
&lt;p&gt;Logger l(&amp;quot;log.txt&amp;quot;);&lt;/p&gt;
&lt;p&gt;As per your article, the CRT initilization will construct l before calling main.&lt;/p&gt;
&lt;p&gt;My question is: what happens if l's constructor throws an exception? &amp;nbsp;Is this bad practice?&lt;/p&gt;
&lt;p&gt;Also, at what point will l's destructor be executed?&lt;/p&gt;
&lt;p&gt;And, on a somewhat related / unrelated subject, can someone direct me to documentation on the __ImageBase construct that the MS C compiler / linker automagically installs into binaries. &amp;nbsp;What other utterly useful fields are available?&lt;/p&gt;
&lt;p&gt;Thanks - great blog.&lt;/p&gt;
</description></item><item><title>re: CRT Initialization</title><link>http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx#1630490</link><pubDate>Fri, 09 Feb 2007 02:49:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1630490</guid><dc:creator>Ben Anderson - MSFT</dc:creator><description>&lt;p&gt;Albert - it is indeed bad practice to create a global variable using a constructor which may throw an exception since you have no way of catching it. &amp;nbsp;I believe the default behavior if an exception is thrown at that point is to terminate, but I'd have to check the standard to be sure.&lt;/p&gt;
&lt;p&gt;However, there is a solution to this problem, which is to construct such an object inside the initializer of a global object and surround the construction in a try/catch block. &amp;nbsp;The pseudocode is something like:&lt;/p&gt;
&lt;p&gt;int InitFunc();&lt;/p&gt;
&lt;p&gt;Logger *l;&lt;/p&gt;
&lt;p&gt;int gDummy = InitFunc();&lt;/p&gt;
&lt;p&gt;int InitFunc()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;try {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;l = new Logger(&amp;quot;log.txt&amp;quot;);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;} catch (...) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// error handling&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;void Cleanup()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;delete l;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;int main()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;...&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Cleanup();&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;The alternative of course would be to not allow the constructor of Logger which is being called to throw an exception. &amp;nbsp;This could be achieved by either not calling throwing code in the constructor, or try/catching and doing error handling inside the constructor. &amp;nbsp;If you are using the logger class elsewhere in your code where you would like it to throw you can always create an overload that doesn't by adding a dummy parmeter like so:&lt;/p&gt;
&lt;p&gt;// nonthrowing constructor&lt;/p&gt;
&lt;p&gt;Logger::Logger(const string&amp;amp; filename, int dummyNoThrow)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;try {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;InitHelp(filename);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;} catch (...) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // error handling&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;// could throw&lt;/p&gt;
&lt;p&gt;Logger::Logger(const string&amp;amp; filename)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;InitHelp(filename);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
</description></item><item><title>re: CRT Initialization</title><link>http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx#1872796</link><pubDate>Tue, 13 Mar 2007 16:45:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1872796</guid><dc:creator>Patrick Scott</dc:creator><description>&lt;p&gt;What is the best pratice for the initialization of a large structure of elements, usually the sturcture is not modified, (communication message structures), with portions needing to be filled in during run time.&lt;/p&gt;
</description></item></channel></rss>