<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Inline Functions question' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Inline Functions question' posted on the 'Beginner C/C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Wed, 19 Jun 2013 22:12:39 -0700</pubDate>
    <lastBuildDate>Wed, 19 Jun 2013 22:12:39 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Inline Functions question</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/411311/411311/inline-functions-question/</link>
      <description>Learning about inline functions and very confused.&lt;br /&gt;
&lt;br /&gt;
When I use an inline function am I &lt;em&gt;not &lt;/em&gt;pushing another activation record onto the stack? If not then how does the inline function know how to return to the function that called it? And where is it exactly if its not on the stack? When the function is copied where is it copied to, RAM? I don't understand this. &lt;br /&gt;
&lt;br /&gt;
If I declare a function inline and then call it multiple times in my program then I will have multiple copies of the function code in my program- I really have no idea what this means. Where does the compiler put all of these copies when it builds the program?&lt;br /&gt;
&lt;br /&gt;
Thanks for any responses.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/beginnercpp/411311/411311/inline-functions-question/</guid>
      <pubDate>Mon, 28 Dec 2009 13:16:11 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: Inline Functions question</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/411311/411344/re-inline-functions-question/#411344</link>
      <description>&lt;span style="color: Blue;"&gt;Compiler simply inserts the code (copies it) into the place of a function call. A simple example:&lt;/span&gt;&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
int SUM (int a, int b)
{
	return a+b;
}
&lt;span style="color: Green;"&gt;//
// Without INLINE
//&lt;/span&gt;
int main ()
{
	int n1,n2;

	printf ("ENTER TWO INTEGER VALUES: ");
	scanf ("%d %d", &amp;amp;n1, &amp;amp;n2);
	printf ("\nSUM OF THESE VALUES: %d", &lt;span style="color: Red;"&gt;SUM (n1, n2)&lt;/span&gt;);
	return 0;
}
&lt;span style="color: Green;"&gt;//
// With INLINE (a simple replacement)
//&lt;/span&gt;
int main ()
{
	int n1,n2;

	printf ("ENTER TWO INTEGER VALUES: ");
	scanf ("%d %d", &amp;amp;n1, &amp;amp;n2);
	printf ("\nSUM OF THESE VALUES: %d", &lt;span style="color: Red;"&gt;n1+n2&lt;/span&gt;);
	return 0;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;span style="color: Blue;"&gt;Also, &lt;em&gt;inline&lt;/em&gt; keyword works mostly in RELEASE build - compiler does it on RELEASE build and not all is inlined. Compiler measures the SIZE of functions and inlines only the functions, which are not large. Also, if a function is very SMALL (like SUM in my example) - you do not need to write &lt;em&gt;inline&lt;/em&gt; for it - it will be inlined automatically, by size. All small functions are inlined this way, just by looking at the size of a function.&lt;/span&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/beginnercpp/411311/411344/re-inline-functions-question/#411344</guid>
      <pubDate>Tue, 29 Dec 2009 05:09:53 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: Inline Functions question</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/411311/411390/re-inline-functions-question/#411390</link>
      <description>Hmm maybe my question comes from a deeper ignorance of how a program is compiled. &lt;br /&gt;
&lt;br /&gt;
If I have:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
inline int SUM (int a, int b)
{
	return a+b;
}

int main ()
{
	int n1,n2;

	printf ("ENTER TWO INTEGER VALUES: ");
	scanf ("%d %d", &amp;amp;n1, &amp;amp;n2);
	printf ("\nSUM OF THESE VALUES: %d", SUM (n1, n2));
	return 0;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
The compiler takes "SUM (n1, n2)" and replaces it with "n1+n2"? How is that replacement made? And how does it make my program bigger?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/beginnercpp/411311/411390/re-inline-functions-question/#411390</guid>
      <pubDate>Wed, 30 Dec 2009 12:43:29 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: Inline Functions question</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/411311/411391/re-inline-functions-question/#411391</link>
      <description>Hmm maybe my question comes from a deeper ignorance of how a program is compiled. &lt;br /&gt;
&lt;br /&gt;
If I have:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
inline int SUM (int a, int b)
{
	return a+b;
}

int main ()
{
	int n1,n2;

	printf ("ENTER TWO INTEGER VALUES: ");
	scanf ("%d %d", &amp;amp;n1, &amp;amp;n2);
	printf ("\nSUM OF THESE VALUES: %d", SUM (n1, n2));
	return 0;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
The compiler takes "SUM (n1, n2)" and replaces it with "n1+n2"? How is that replacement made? And how does it make my program bigger?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/beginnercpp/411311/411391/re-inline-functions-question/#411391</guid>
      <pubDate>Wed, 30 Dec 2009 12:45:20 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: Inline Functions question</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/411311/411416/re-inline-functions-question/#411416</link>
      <description>&lt;span style="color: Blue;"&gt;The replacement is made when compiler links all together - only at this moment it can see the function size. Then the Assembly code of the function is placed instead of a function call. When code runs - it is already been replaced. The program gets larger in the case you are using a lot of calls to SUM (inlined) function. Just one call will not make it much larger - maybe a few bytes. But with inline functions you get faster code, because there is no CALL/RETURN codes. However, modern CPUs are very fast on first 16 levels of CALL/RET instructions and if code goes deeper in calls, then it will slow down, but not in very significant way - few CPU clocks (and they come 3.2 billion per second!).&lt;/span&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/beginnercpp/411311/411416/re-inline-functions-question/#411416</guid>
      <pubDate>Thu, 31 Dec 2009 05:44:34 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: Inline Functions question</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/411311/411417/re-inline-functions-question/#411417</link>
      <description>Well that makes things a bit clearer, but it seems like I still have to study this a bit more myself to fully understand it.&lt;br /&gt;
&lt;br /&gt;
Thanks.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/beginnercpp/411311/411417/re-inline-functions-question/#411417</guid>
      <pubDate>Thu, 31 Dec 2009 06:58:31 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
  </channel>
</rss>