<?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 for c/c++ programming by examples</title>
	<atom:link href="http://cc.byexamples.com/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://cc.byexamples.com</link>
	<description>we share the c/c++ coding by examples</description>
	<lastBuildDate>Wed, 03 Mar 2010 17:08:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Comment on simple callback function by rakesh</title>
		<link>http://cc.byexamples.com/2007/10/11/simple-callback-function/comment-page-1/#comment-1960</link>
		<dc:creator>rakesh</dc:creator>
		<pubDate>Wed, 03 Mar 2010 17:08:01 +0000</pubDate>
		<guid isPermaLink="false">http://cc.byexamples.com/20071011/simple-callback-function/#comment-1960</guid>
		<description>its not the example of a call back function.it is an example of function pointer</description>
		<content:encoded><![CDATA[<p>its not the example of a call back function.it is an example of function pointer</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on simple callback function by rakesh</title>
		<link>http://cc.byexamples.com/2007/10/11/simple-callback-function/comment-page-1/#comment-1959</link>
		<dc:creator>rakesh</dc:creator>
		<pubDate>Wed, 03 Mar 2010 17:05:55 +0000</pubDate>
		<guid isPermaLink="false">http://cc.byexamples.com/20071011/simple-callback-function/#comment-1959</guid>
		<description>I have a doubt.

i can call the function &quot;cbfunc(myst *mt)&quot; directly.
then why i am assigning &quot;cbfunc(myst *mt)&quot;  function to &quot;callback&quot; function pointer &amp; then calling it.</description>
		<content:encoded><![CDATA[<p>I have a doubt.</p>
<p>i can call the function &#8220;cbfunc(myst *mt)&#8221; directly.<br />
then why i am assigning &#8220;cbfunc(myst *mt)&#8221;  function to &#8220;callback&#8221; function pointer &amp; then calling it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on GNU readline: Implement Custom Auto-complete by Okki</title>
		<link>http://cc.byexamples.com/2008/06/16/gnu-readline-implement-custom-auto-complete/comment-page-1/#comment-1957</link>
		<dc:creator>Okki</dc:creator>
		<pubDate>Wed, 03 Mar 2010 11:28:14 +0000</pubDate>
		<guid isPermaLink="false">http://cc.byexamples.com/?p=41#comment-1957</guid>
		<description>to prevent a whitespace at the end of the completed command, just set
&lt;code&gt;rl_completion_append_character = &#039;&#039;;&lt;/code&gt;

okki</description>
		<content:encoded><![CDATA[<p>to prevent a whitespace at the end of the completed command, just set<br />
<code>rl_completion_append_character = '';</code></p>
<p>okki</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on create a timer by Indie</title>
		<link>http://cc.byexamples.com/2007/03/14/create-a-timer/comment-page-1/#comment-1956</link>
		<dc:creator>Indie</dc:creator>
		<pubDate>Fri, 26 Feb 2010 17:42:31 +0000</pubDate>
		<guid isPermaLink="false">http://cc.byexamples.com/20070314/create-a-timer/#comment-1956</guid>
		<description>Take a look at these two example of how to create a timer using a semaphore and the alarm signal.

http://www.ibm.com/developerworks/library/l-osmig3.html#N101FA
http://linux.die.net/man/3/sem_wait</description>
		<content:encoded><![CDATA[<p>Take a look at these two example of how to create a timer using a semaphore and the alarm signal.</p>
<p><a href="http://www.ibm.com/developerworks/library/l-osmig3.html#N101FA" rel="nofollow">http://www.ibm.com/developerworks/library/l-osmig3.html#N101FA</a><br />
<a href="http://linux.die.net/man/3/sem_wait" rel="nofollow">http://linux.die.net/man/3/sem_wait</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on nanosleep is better than sleep and usleep by dekkard</title>
		<link>http://cc.byexamples.com/2007/05/25/nanosleep-is-better-than-sleep-and-usleep/comment-page-1/#comment-1955</link>
		<dc:creator>dekkard</dc:creator>
		<pubDate>Fri, 26 Feb 2010 09:06:58 +0000</pubDate>
		<guid isPermaLink="false">http://cc.byexamples.com/20070525/nanosleep-is-better-than-sleep-and-usleep/#comment-1955</guid>
		<description>Here&#039;s what&#039;s cleaner and better:

&lt;code&gt;
void GuaranteedSleep(uint32_t msec)
{
	struct timespec timeout0;
	struct timespec timeout1;
	struct timespec* tmp;
	struct timespec* t0 = &timeout0;
	struct timespec* t1 = &timeout1;

	t0-&gt;tv_sec = msec / 1000;
	t0-&gt;tv_nsec = (msec % 1000) * (1000 * 1000);

	while ((nanosleep(t0, t1) == (-1)) &amp;&amp; (errno == EINTR))
	{
		tmp = t0;
		t0 = t1;
		t1 = tmp;
	}
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Here&#8217;s what&#8217;s cleaner and better:</p>
<p><code><br />
void GuaranteedSleep(uint32_t msec)<br />
{<br />
	struct timespec timeout0;<br />
	struct timespec timeout1;<br />
	struct timespec* tmp;<br />
	struct timespec* t0 = &#038;timeout0;<br />
	struct timespec* t1 = &timeout1;</p>
<p>	t0-&gt;tv_sec = msec / 1000;<br />
	t0-&gt;tv_nsec = (msec % 1000) * (1000 * 1000);</p>
<p>	while ((nanosleep(t0, t1) == (-1)) &amp;&amp; (errno == EINTR))<br />
	{<br />
		tmp = t0;<br />
		t0 = t1;<br />
		t1 = tmp;<br />
	}<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on GNU readline: Implement Custom Auto-complete by Jason</title>
		<link>http://cc.byexamples.com/2008/06/16/gnu-readline-implement-custom-auto-complete/comment-page-1/#comment-1954</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Fri, 26 Feb 2010 01:11:23 +0000</pubDate>
		<guid isPermaLink="false">http://cc.byexamples.com/?p=41#comment-1954</guid>
		<description>Thank you so much, this really made life easier.

When I actually constructed this into my program, I ran across a couple problems.  (I&#039;m on a mac, using standard C++)

First is, my compiler complained it did not know what rl_abort was.  I searched the web, couldn&#039;t find anything, checked out the readline doc, and they recommend: rl_insert.  Tried that, fixed the compile issue.

After I got the basic program working with autocomplete I integrated this into my application and got a segfault whenever I hit tab.  

This took a while for me to set up gdb and walk through this but I traced it back to the array:
char* cmd [] ={ &quot;hello&quot;, &quot;world&quot;, &quot;hell&quot; ,&quot;word&quot;, &quot;quit&quot;, &quot; &quot; };

and

while ((name = cmd[list_index])

I&#039;m not sure if this was something wrong with my implementation (I copied your code verbatim, even the cmd string), but the while loop overruns the array.  I added a return character to the array, identifying this as the end of the array, and checking for this character before continuing.  Ex:

char* cmd [] ={ &quot;hello&quot;, &quot;world&quot;, &quot;hell&quot; ,&quot;word&quot;, &quot;quit&quot;, &quot; &quot;, &quot;\r&quot; };  and 

while ((name = cmd[list_index]) &amp;&amp; strncmp(cmd[list_index],&quot;\r&quot;, 1) != 0)

Thanks again, everything is working great now.</description>
		<content:encoded><![CDATA[<p>Thank you so much, this really made life easier.</p>
<p>When I actually constructed this into my program, I ran across a couple problems.  (I&#8217;m on a mac, using standard C++)</p>
<p>First is, my compiler complained it did not know what rl_abort was.  I searched the web, couldn&#8217;t find anything, checked out the readline doc, and they recommend: rl_insert.  Tried that, fixed the compile issue.</p>
<p>After I got the basic program working with autocomplete I integrated this into my application and got a segfault whenever I hit tab.  </p>
<p>This took a while for me to set up gdb and walk through this but I traced it back to the array:<br />
char* cmd [] ={ &#8220;hello&#8221;, &#8220;world&#8221;, &#8220;hell&#8221; ,&#8221;word&#8221;, &#8220;quit&#8221;, &#8221; &#8221; };</p>
<p>and</p>
<p>while ((name = cmd[list_index])</p>
<p>I&#8217;m not sure if this was something wrong with my implementation (I copied your code verbatim, even the cmd string), but the while loop overruns the array.  I added a return character to the array, identifying this as the end of the array, and checking for this character before continuing.  Ex:</p>
<p>char* cmd [] ={ &#8220;hello&#8221;, &#8220;world&#8221;, &#8220;hell&#8221; ,&#8221;word&#8221;, &#8220;quit&#8221;, &#8221; &#8220;, &#8220;\r&#8221; };  and </p>
<p>while ((name = cmd[list_index]) &amp;&amp; strncmp(cmd[list_index],&#8221;\r&#8221;, 1) != 0)</p>
<p>Thanks again, everything is working great now.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on sscanf, scan input from a string by Lalith</title>
		<link>http://cc.byexamples.com/2007/01/18/sscanf-scan-input-from-a-string-2/comment-page-1/#comment-1953</link>
		<dc:creator>Lalith</dc:creator>
		<pubDate>Fri, 12 Feb 2010 11:44:14 +0000</pubDate>
		<guid isPermaLink="false">http://cc.byexamples.com/20070118/sscanf-scan-input-from-a-string-2/#comment-1953</guid>
		<description>you shouldn&#039;t try giving &amp;a[0] try giving jus a[0] for scanning as both are same...!!</description>
		<content:encoded><![CDATA[<p>you shouldn&#8217;t try giving &amp;a[0] try giving jus a[0] for scanning as both are same&#8230;!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on create a timer by SomeLurker</title>
		<link>http://cc.byexamples.com/2007/03/14/create-a-timer/comment-page-1/#comment-1952</link>
		<dc:creator>SomeLurker</dc:creator>
		<pubDate>Wed, 10 Feb 2010 11:02:03 +0000</pubDate>
		<guid isPermaLink="false">http://cc.byexamples.com/20070314/create-a-timer/#comment-1952</guid>
		<description>mysurface: while it might be true that &quot;because the programs suppose to process for other things within this 5 seconds&quot; is of concern, the example given here still is VERY problematic since it&#039;s a busy loop.

If one needs background processing while waiting, then one would do much better by using a proper multi-event capable select() mechanism in the app.
If one needs such handling, then this is the way to go.
If one for some reason doesn&#039;t want to use a select()-based mechanism, then launch one or more worker threads.
But simply burning CPU for CPU upgrading&#039;s sake (the infamous Wintel behaviour) is a no-no.</description>
		<content:encoded><![CDATA[<p>mysurface: while it might be true that &#8220;because the programs suppose to process for other things within this 5 seconds&#8221; is of concern, the example given here still is VERY problematic since it&#8217;s a busy loop.</p>
<p>If one needs background processing while waiting, then one would do much better by using a proper multi-event capable select() mechanism in the app.<br />
If one needs such handling, then this is the way to go.<br />
If one for some reason doesn&#8217;t want to use a select()-based mechanism, then launch one or more worker threads.<br />
But simply burning CPU for CPU upgrading&#8217;s sake (the infamous Wintel behaviour) is a no-no.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Non-blocking user input in loop without ncurses. by hoppang</title>
		<link>http://cc.byexamples.com/2007/04/08/non-blocking-user-input-in-loop-without-ncurses/comment-page-1/#comment-1950</link>
		<dc:creator>hoppang</dc:creator>
		<pubDate>Fri, 29 Jan 2010 08:23:30 +0000</pubDate>
		<guid isPermaLink="false">http://cc.byexamples.com/20070408/non-blocking-user-input-in-loop-without-ncurses/#comment-1950</guid>
		<description>Fascinating. it&#039;s exactly what i want. thanks.</description>
		<content:encoded><![CDATA[<p>Fascinating. it&#8217;s exactly what i want. thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on nanosleep is better than sleep and usleep by Sorcerer88</title>
		<link>http://cc.byexamples.com/2007/05/25/nanosleep-is-better-than-sleep-and-usleep/comment-page-1/#comment-1948</link>
		<dc:creator>Sorcerer88</dc:creator>
		<pubDate>Sat, 05 Dec 2009 16:53:09 +0000</pubDate>
		<guid isPermaLink="false">http://cc.byexamples.com/20070525/nanosleep-is-better-than-sleep-and-usleep/#comment-1948</guid>
		<description>sorry, should have tested before, small error in my post before. this should work:
 
void msleep(int ms) {
  struct timespec time;
  time.tv_sec = ms / 1000;
  time.tv_nsec = (ms % 1000) * (1000 * 1000);
  nanosleep(&amp;time,NULL);
}</description>
		<content:encoded><![CDATA[<p>sorry, should have tested before, small error in my post before. this should work:</p>
<p>void msleep(int ms) {<br />
  struct timespec time;<br />
  time.tv_sec = ms / 1000;<br />
  time.tv_nsec = (ms % 1000) * (1000 * 1000);<br />
  nanosleep(&amp;time,NULL);<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
