<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Recursion Depth Counting</title>
	<atom:link href="http://blog.froglogic.com/2007/04/recursion-depth-counting/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.froglogic.com/2007/04/recursion-depth-counting/</link>
	<description>A company weblog</description>
	<lastBuildDate>Tue, 28 Dec 2010 10:34:36 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
	<item>
		<title>By: Term Paper</title>
		<link>http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-44664</link>
		<dc:creator>Term Paper</dc:creator>
		<pubDate>Tue, 28 Dec 2010 10:34:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-44664</guid>
		<description>The Recursion Depth Counting is really nice thing to get know about and I think this good to have such information for knowledge to gain, and to make most of it.</description>
		<content:encoded><![CDATA[<p>The Recursion Depth Counting is really nice thing to get know about and I think this good to have such information for knowledge to gain, and to make most of it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Term Papers</title>
		<link>http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-43368</link>
		<dc:creator>Term Papers</dc:creator>
		<pubDate>Tue, 07 Dec 2010 11:27:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-43368</guid>
		<description>It&#039;s a very good post.I am very happy to learn the things from the article.I will continue to read your articles. And please keep more posting like this , thanks</description>
		<content:encoded><![CDATA[<p>It&#8217;s a very good post.I am very happy to learn the things from the article.I will continue to read your articles. And please keep more posting like this , thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Bieber</title>
		<link>http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-39400</link>
		<dc:creator>David Bieber</dc:creator>
		<pubDate>Sat, 28 Aug 2010 05:57:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-39400</guid>
		<description>The #1 problem is that it’s very easy to forget to decrement the recursionDepth  counter variable in case you return from the function somewhere else than the end of it. I happen to do that very very often, and I know myself well enough to know that I’ll probably forget to care about the recursionDepth  variable if I add some new code (with a new return statement) in the middle of that function. &lt;a href=&quot;http://tavateaweb.com/&quot; rel=&quot;nofollow&quot;&gt;tava tea&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>The #1 problem is that it’s very easy to forget to decrement the recursionDepth  counter variable in case you return from the function somewhere else than the end of it. I happen to do that very very often, and I know myself well enough to know that I’ll probably forget to care about the recursionDepth  variable if I add some new code (with a new return statement) in the middle of that function. <a href="http://tavateaweb.com/">tava tea</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie Allen</title>
		<link>http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-32439</link>
		<dc:creator>Jamie Allen</dc:creator>
		<pubDate>Wed, 06 Jan 2010 07:11:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-32439</guid>
		<description>I was a supposed to take up Java Script as an extra course for the company that I was applying to did not find my &lt;a href=&quot;http://www.resumesplanet.com&quot; rel=&quot;nofollow&quot;&gt;resume&lt;/a&gt; that impressive. Its a good thing I did not continue for there are a lot of other way to learn about programming languages, especially on the web.</description>
		<content:encoded><![CDATA[<p>I was a supposed to take up Java Script as an extra course for the company that I was applying to did not find my <a href="http://www.resumesplanet.com">resume</a> that impressive. Its a good thing I did not continue for there are a lot of other way to learn about programming languages, especially on the web.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PAF</title>
		<link>http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-203</link>
		<dc:creator>PAF</dc:creator>
		<pubDate>Wed, 18 Apr 2007 00:08:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-203</guid>
		<description>better late than never: what about making your template argument a void*, and use the function itself as the template argument. You would get a separate object for each function, clashing only if the two functions are ... the same.
Maybe this would work with a char* template argument and then using some predefined macro to make a unique string for each function, like __FILE__ #__LINE__

In these cases, thread-safety would have to be implemented in the RecursionCounter itself.</description>
		<content:encoded><![CDATA[<p>better late than never: what about making your template argument a void*, and use the function itself as the template argument. You would get a separate object for each function, clashing only if the two functions are &#8230; the same.<br />
Maybe this would work with a char* template argument and then using some predefined macro to make a unique string for each function, like __FILE__ #__LINE__</p>
<p>In these cases, thread-safety would have to be implemented in the RecursionCounter itself.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Knic Knic</title>
		<link>http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-185</link>
		<dc:creator>Knic Knic</dc:creator>
		<pubDate>Sat, 14 Apr 2007 19:31:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-185</guid>
		<description>Personally I always use a different solution (of course it adds to stack bloat, but whatever) but it has served me well in programming competitions. Also the compiler wont catch it if you make a call to f without using the parameter recursionDepth, which can lead to annoying bugs. However default parameters never bit in this case, because I pretty much always have a depth in there.

void f(int recursionDepth = 0)
{
    ++recursionDepth;    

    printf( &quot;Recursion depth is: %dn&quot;, recursionDepth );
    // Lots of code here; for each return path, don&#039;t forget
    // to decrement recursionDepth!    


}</description>
		<content:encoded><![CDATA[<p>Personally I always use a different solution (of course it adds to stack bloat, but whatever) but it has served me well in programming competitions. Also the compiler wont catch it if you make a call to f without using the parameter recursionDepth, which can lead to annoying bugs. However default parameters never bit in this case, because I pretty much always have a depth in there.</p>
<p>void f(int recursionDepth = 0)<br />
{<br />
    ++recursionDepth;    </p>
<p>    printf( &#8220;Recursion depth is: %dn&#8221;, recursionDepth );<br />
    // Lots of code here; for each return path, don&#8217;t forget<br />
    // to decrement recursionDepth!    </p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rix</title>
		<link>http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-173</link>
		<dc:creator>rix</dc:creator>
		<pubDate>Wed, 11 Apr 2007 07:33:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-173</guid>
		<description>I would make use of C99&#039;s __func__ , or __PRETTY_FUNCTION__ (GCC only, but how useful) from a macro, something like:

class RecursionCounter
{
public:
  inline RecursionCounter(string funcname) { counter[funcname]++; }
  ...
private:
  static std::map counter;
};

#define RECURSION_COUNTER RecursionCounter _counter(__func__)

void f()
{
  RECURSION_COUNTER;
  ...
}</description>
		<content:encoded><![CDATA[<p>I would make use of C99&#8242;s __func__ , or __PRETTY_FUNCTION__ (GCC only, but how useful) from a macro, something like:</p>
<p>class RecursionCounter<br />
{<br />
public:<br />
  inline RecursionCounter(string funcname) { counter[funcname]++; }<br />
  &#8230;<br />
private:<br />
  static std::map counter;<br />
};</p>
<p>#define RECURSION_COUNTER RecursionCounter _counter(__func__)</p>
<p>void f()<br />
{<br />
  RECURSION_COUNTER;<br />
  &#8230;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kblindert</title>
		<link>http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-167</link>
		<dc:creator>Kblindert</dc:creator>
		<pubDate>Tue, 10 Apr 2007 22:35:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-167</guid>
		<description>With some spicy invariants added :)


struct algo
{
 int rcount;
 algo() : rcount(0) {}
 // Recursive alorithm entrypoint
 // Assures algoriithm isn&#039;t started yet.
 f() { 
   assert( rcount == 0 );
   f_intern();
   assert( rcount == 0 );
 }
private:
 struct reclvl { 
     reclvl(int&amp; _r) : r(++_r) {}
     ~reclvl() { --r; }
    int level() const { return r; }
    private:
    int&amp; r;
 };
 f_intern()
 {
     reclvl( a_rcount );

     do_stuff().

 }
};</description>
		<content:encoded><![CDATA[<p>With some spicy invariants added <img src='http://blog.froglogic.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>struct algo<br />
{<br />
 int rcount;<br />
 algo() : rcount(0) {}<br />
 // Recursive alorithm entrypoint<br />
 // Assures algoriithm isn&#8217;t started yet.<br />
 f() {<br />
   assert( rcount == 0 );<br />
   f_intern();<br />
   assert( rcount == 0 );<br />
 }<br />
private:<br />
 struct reclvl {<br />
     reclvl(int&amp; _r) : r(++_r) {}<br />
     ~reclvl() { &#8211;r; }<br />
    int level() const { return r; }<br />
    private:<br />
    int&amp; r;<br />
 };<br />
 f_intern()<br />
 {<br />
     reclvl( a_rcount );</p>
<p>     do_stuff().</p>
<p> }<br />
};</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-162</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 10 Apr 2007 21:56:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-162</guid>
		<description>what about passing a ref on the counter to the class (int&#039;s just here to increment the value;

class incrementor {
public:
  incrementor(int&amp; i) : m_i(i) {m_i++;}
  ~incrementor() {m_i--;}
  int&amp; m_i;
}

and the function is

void f() {
  static int recursionDepth=0;
  incrementor incr(recursionDepth);

  printf( &quot;Recursion depth: %d\n&quot;, recursionDepth );
}</description>
		<content:encoded><![CDATA[<p>what about passing a ref on the counter to the class (int&#8217;s just here to increment the value;</p>
<p>class incrementor {<br />
public:<br />
  incrementor(int&amp; i) : m_i(i) {m_i++;}<br />
  ~incrementor() {m_i&#8211;;}<br />
  int&amp; m_i;<br />
}</p>
<p>and the function is</p>
<p>void f() {<br />
  static int recursionDepth=0;<br />
  incrementor incr(recursionDepth);</p>
<p>  printf( &#8220;Recursion depth: %d\n&#8221;, recursionDepth );<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-160</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 10 Apr 2007 17:20:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.froglogic.com/2007/04/recursion-depth-counting/#comment-160</guid>
		<description>You could try using Boost.Fusion&#039;s compile-time map using 

class MY_F_COUNTER;
class MY_G_COUNTER;
...

as keys to get at the run-time counters.</description>
		<content:encoded><![CDATA[<p>You could try using Boost.Fusion&#8217;s compile-time map using </p>
<p>class MY_F_COUNTER;<br />
class MY_G_COUNTER;<br />
&#8230;</p>
<p>as keys to get at the run-time counters.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

