<?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>Why doesn't C# have an 'inline' keyword?</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx</link><description>I got this question in email today, and I thought I'd share my response. For those of you who don't know, the 'inline' keyword in the C language was designed to control whether the compiler inlined a function into the calling function. For example, if</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Why doesn't C# have an 'inline' keyword?</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#64697</link><pubDate>Thu, 29 Jan 2004 22:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:64697</guid><dc:creator>Joeseph </dc:creator><description>Here's a related question.&lt;br&gt;&lt;br&gt;When you create a property in .NET, we create it something like this.&lt;br&gt;&lt;br&gt;private int _num; &lt;br&gt;public int TheNumber&lt;br&gt;{&lt;br&gt;  get { return this._num; }&lt;br&gt;  set { this._num = value; }&lt;br&gt;}&lt;br&gt;&lt;br&gt;The compiler will create the appropriate get_ and set_ accessor functions.&lt;br&gt;My question is this. &lt;br&gt;&lt;br&gt;If you are creating, say... a control, and using your properties internally, is it &lt;br&gt;more effecient to use the private member variable, or to call the property explicitly? Basically, should&lt;br&gt;you do ....&lt;br&gt;int temp = this.TheNumber &lt;br&gt;or....&lt;br&gt;int temp = this._num;&lt;br&gt;&lt;br&gt;This is assuming that the getter function is just returning the value of the private member. If additional logic was needed, then of course you would call the accessor. But if you're just returning a simple value, I would think you could skip the overhead of calling the function. I doubt it would save much on 1 or 2 calls, but I've seen code similar to this many times. &lt;br&gt;	&lt;br&gt;	for ( int i = 0; i != 1000; i++ )&lt;br&gt;	{&lt;br&gt;	  if ( this.TheNumber &amp;gt; 8 )&lt;br&gt;		// do something&lt;br&gt;	}&lt;br&gt;&lt;br&gt;In the above example, there would be a 1000 calls to the accessor function, which seems less effecient than 1000 calls to just check the value of a variable.&lt;br&gt;&lt;br&gt;Encapsulation wise, it is far better to call the property directly, but is it better performance wise to call the private member directly?&lt;br&gt;&lt;br&gt;I know there is no simple answer, but I'm curious as to whether or not the compiler helps out here.</description></item><item><title>re: Why doesn't C# have an 'inline' keyword?</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#64699</link><pubDate>Thu, 29 Jan 2004 22:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:64699</guid><dc:creator>Jason Salas</dc:creator><description>My desires are a bit more simplistic - I've just always wished C# would have something similar to VB.NET's &amp;quot;With&amp;quot; keyword.  :)</description></item><item><title>re: Why doesn't C# have an 'inline' keyword?</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#64711</link><pubDate>Thu, 29 Jan 2004 23:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:64711</guid><dc:creator>W Poust</dc:creator><description>Several years ago our software group had the same discussion about inline functions.  The senior developers made the same point that the compiler does a better job at optimizing.  Actually between the compiler and the CPU instruction pipeline optimizations, its a non-trivial issue to understand.  We told the gungho performance geeks that we wouldn't accept inline but if they were serious they could write asm blocks.  Funny how none of the performance people took us up on the offer.</description></item><item><title>.NET method inlining</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#64744</link><pubDate>Fri, 30 Jan 2004 04:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:64744</guid><dc:creator>Jeff Key</dc:creator><description /></item><item><title>re: Why doesn't C# have an 'inline' keyword?</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#64818</link><pubDate>Fri, 30 Jan 2004 05:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:64818</guid><dc:creator>Scott Mitchell</dc:creator><description>What would happen in VC++ with:&lt;br&gt;&lt;br&gt;__forceinline void Factorial(int x)&lt;br&gt;{ &lt;br&gt;  if (x == 1) &lt;br&gt;     return 1;&lt;br&gt;  else&lt;br&gt;     return x * Factorial(x-1); }&lt;br&gt;}&lt;br&gt;&lt;br&gt;???  ;-)</description></item><item><title>re: Why doesn't C# have an 'inline' keyword?</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#64832</link><pubDate>Fri, 30 Jan 2004 05:57:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:64832</guid><dc:creator>Eric</dc:creator><description>Scott,&lt;br&gt;&lt;br&gt;Human sacrifices, dogs and cats living together! Mass hysteria!</description></item><item><title>CLR Inlining</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#64913</link><pubDate>Fri, 30 Jan 2004 12:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:64913</guid><dc:creator>Paul's Imaginary Friend</dc:creator><description /></item><item><title>Eric Gunnerson discusses Inlining</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#66265</link><pubDate>Mon, 02 Feb 2004 21:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:66265</guid><dc:creator>Code/Tea/Etc...</dc:creator><description /></item><item><title>re: Why doesn't C# have an 'inline' keyword?</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#67467</link><pubDate>Wed, 04 Feb 2004 17:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:67467</guid><dc:creator>James Curran</dc:creator><description>Scott,&lt;br&gt;  VC++ has an internal inline recursion limit (what? you think you were the first to think of trying that?).  It default's to 8 (I think), but can be set higher with a #pragma.&lt;br&gt;&lt;br&gt;Basically, the following code:&lt;br&gt;   int a = Factorial(3);&lt;br&gt;   int b = Factorial(7);&lt;br&gt;   int c = Factorial(10);&lt;br&gt;can conpiled as if written:&lt;br&gt;   int a = 6;&lt;br&gt;   int b = 5040;&lt;br&gt;   int c = 1814400 * Factorial(2);&lt;br&gt;&lt;br&gt;And even in the out-of-line Factorial it has to create, it tries to inline some of the recursion.  It's really fascinating to see the assembly code generated by that.&lt;br&gt;</description></item><item><title>re: Why doesn't C# have an 'inline' keyword?</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#67734</link><pubDate>Thu, 05 Feb 2004 02:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:67734</guid><dc:creator>Adnan Masood</dc:creator><description>I appreciate Eric's memory with GhostBusters.&lt;br&gt;&lt;br&gt;In reference to Microsoft Specific VC++ compiler, Scott's code would not be inlined since &amp;quot;its  recursive and not accompanied by #pragma inline_recursion(on)&amp;quot;&lt;br&gt;&lt;br&gt;C++ Language Reference   &lt;br&gt;inline, __inline, __forceinline&lt;br&gt;&lt;a target="_new" href="http://msdn.microsoft.com/library/en-us/vclang/html/_pluslang_inline_specifier.asp?frame=true"&gt;http://msdn.microsoft.com/library/en-us/vclang/html/_pluslang_inline_specifier.asp?frame=true&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;Even with __forceinline, the compiler cannot inline code in all circumstances. The compiler cannot inline a function if: &lt;br&gt;&lt;br&gt;The function or its caller is compiled with /Ob0 (the default option for debug builds). &lt;br&gt;The function and the caller use different types of exception handling (C++ exception handling in one, structured exception handling in the other). &lt;br&gt;The function has a variable argument list. &lt;br&gt;The function uses inline assembly, unless compiled with /Og, /Ox, /O1, or /O2. &lt;br&gt;The function returns an unwindable object by value, when compiled with /GX, /EHs, or /EHa. &lt;br&gt;The function receives an unwindable copy-constructed object passed by value, when compiled with /GX, /EHs,, or /EHa. &lt;br&gt;The function is recursive and not accompanied by #pragma inline_recursion(on). With the pragma, recursive functions can be inlined to a default depth of eight calls. To change the inlining depth, use inline_depth pragma. &lt;br&gt;The function is virtual and is called virtually. Direct calls to virtual functions can be inlined. &lt;br&gt;The program takes the address of the function and the call is made via the pointer to the function. Direct calls to functions that have had their address taken can be inlined. &lt;br&gt;The function is also marked with the naked __declspec modifier. &lt;br&gt;&lt;br&gt;If the compiler cannot inline a function declared with __forceinline, it generates a level 1 warning (4714).</description></item><item><title>re: Why doesn't C# have an 'inline' keyword?</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#67961</link><pubDate>Thu, 05 Feb 2004 12:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:67961</guid><dc:creator>moo</dc:creator><description>JIT Inlining, is this set in stone on the first JIT or can it rejit if it realises its better inlined based on usage during runtime?&lt;br&gt;&lt;br&gt;If not would this be implemented in future?  Obviously you dont want it to spend alot of time reJITting a method to inline or not inline based on profiling data if its oscilating about.</description></item><item><title>re: Why doesn't C# have an 'inline' keyword?</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#67962</link><pubDate>Thu, 05 Feb 2004 12:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:67962</guid><dc:creator>moo</dc:creator><description>The world MIGHT end and planets MAY collide.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;# re: Why doesn't C# have an 'inline' keyword? 1/29/2004 9:24 PM Scott Mitchell &lt;br&gt;What would happen in VC++ with: &lt;br&gt;&lt;br&gt;__forceinline void Factorial(int x) &lt;br&gt;{ &lt;br&gt;if (x == 1) &lt;br&gt;return 1; &lt;br&gt;else &lt;br&gt;return x * Factorial(x-1); } &lt;br&gt;} &lt;br&gt;&lt;br&gt;??? ;-) &lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Why doesn't C# have an 'inline' keyword?</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#68265</link><pubDate>Thu, 05 Feb 2004 22:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:68265</guid><dc:creator>Adnan Masood</dc:creator><description>Also, the code was faulty since factorial is defined for n &amp;gt;= 0 and for 0!=1 by definition. (could be calculated too.)&lt;br&gt;&lt;br&gt;n! = n*(n-1)! for n &amp;gt; 1&lt;br&gt;&lt;br&gt;Therefore it should have been...&lt;br&gt;&lt;br&gt;__forceinline void Factorial(int x) &lt;br&gt;{ &lt;br&gt;if (x &amp;lt; 1) &lt;br&gt;return 1; &lt;br&gt;else &lt;br&gt;return x * Factorial(x-1); } &lt;br&gt;} </description></item><item><title>re: Why doesn't C# have an 'inline' keyword?</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#120117</link><pubDate>Mon, 26 Apr 2004 09:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:120117</guid><dc:creator>John Schultz</dc:creator><description>Adnan, the original Factorial() author's real question was &amp;quot;What happens with __forceinline and recursive fcns?&amp;quot;, not &amp;quot;Does this code implement factorial right?&amp;quot;&lt;br&gt;&lt;br&gt;Since you needlessly picked on someone else's pseudo code snippet, I'll pick on yours:&lt;br&gt;&lt;br&gt;Your fix is only partial -- you still quietly give an incorrect answer for negatives, you don't detect overflow and you return void!&lt;br&gt;&lt;br&gt;Of course the best implementation of Factorial, as you noted, is to just have an array of the first 20 pre-computed, 64 bit answers and use the argument as the offset.&lt;br&gt;</description></item><item><title>Eric Gunnerson discusses Inlining</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#220108</link><pubDate>Wed, 25 Aug 2004 13:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:220108</guid><dc:creator>Code/Tea/Etc.</dc:creator><description /></item><item><title>MBA</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#324532</link><pubDate>Sat, 18 Dec 2004 18:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:324532</guid><dc:creator>MBA</dc:creator><description>Helpful For MBA Fans.</description></item><item><title>re: How many bad developers are there in the world?</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#447746</link><pubDate>Thu, 04 Aug 2005 20:30:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:447746</guid><dc:creator>Software/Technology Discussion</dc:creator><description /></item><item><title>re: How many bad developers are there in the world?</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#447931</link><pubDate>Fri, 05 Aug 2005 04:27:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:447931</guid><dc:creator>Software/Technology Discussion</dc:creator><description /></item><item><title>Re: Inline routines</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#8568335</link><pubDate>Mon, 02 Jun 2008 00:40:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8568335</guid><dc:creator>Channel 9</dc:creator><description>&lt;p&gt;.Net inlines everything it can&lt;/p&gt;
</description></item><item><title>C# Inline Methods and Optimization | #2782 - Agile software development and best practices for building Microsoft .NET applications.</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#8879886</link><pubDate>Wed, 20 Aug 2008 01:11:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8879886</guid><dc:creator>C# Inline Methods and Optimization | #2782 - Agile software development and best practices for building Microsoft .NET applications.</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.ademiller.com/blogs/tech/2008/08/c-inline-methods-and-optimization/"&gt;http://www.ademiller.com/blogs/tech/2008/08/c-inline-methods-and-optimization/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title> Eric Gunnerson s C Compendium Why doesn t C have an inline keyword | Green Tea Fat Burner</title><link>http://blogs.msdn.com/ericgu/archive/2004/01/29/64644.aspx#9706907</link><pubDate>Mon, 08 Jun 2009 05:37:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9706907</guid><dc:creator> Eric Gunnerson s C Compendium Why doesn t C have an inline keyword | Green Tea Fat Burner</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://greenteafatburner.info/story.php?id=3567"&gt;http://greenteafatburner.info/story.php?id=3567&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>