<?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: A &#039;C&#039; Test: The 0&#215;10 best questions for would-be embedded programmers (reprised)</title>
	<atom:link href="http://embeddedgurus.com/stack-overflow/2009/09/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/feed/" rel="self" type="application/rss+xml" />
	<link>http://embeddedgurus.com/stack-overflow/2009/09/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/</link>
	<description>Thoughts on embedded systems by Nigel Jones</description>
	<lastBuildDate>Mon, 06 Sep 2010 14:57:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ian Johns</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/09/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/comment-page-1/#comment-420</link>
		<dc:creator>Ian Johns</dc:creator>
		<pubDate>Fri, 05 Mar 2010 03:26:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/09/15/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/#comment-420</guid>
		<description>&gt; one can indeed call a static function from another module (translation unit to be very precise), by simply calling it via a function pointer. Will this work? – sure, is it nuts? – yes

It isn&#039;t nuts at all.  For instance, an application could use a callback handler/manager that executes functions via pointers when certain configured events occur.  A module may configure an event callback passing one of its own private/static functions.  So although the static function may execute only when called via function pointer by the external callback handler, the static function may only be directly accessed/configured/etc.  by its own module.

This type of callback mechanism is very useful &amp; usage with static functions is not unreasonable.</description>
		<content:encoded><![CDATA[<p>&gt; one can indeed call a static function from another module (translation unit to be very precise), by simply calling it via a function pointer. Will this work? – sure, is it nuts? – yes</p>
<p>It isn&#8217;t nuts at all.  For instance, an application could use a callback handler/manager that executes functions via pointers when certain configured events occur.  A module may configure an event callback passing one of its own private/static functions.  So although the static function may execute only when called via function pointer by the external callback handler, the static function may only be directly accessed/configured/etc.  by its own module.</p>
<p>This type of callback mechanism is very useful &amp; usage with static functions is not unreasonable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel Jones</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/09/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/comment-page-1/#comment-285</link>
		<dc:creator>Nigel Jones</dc:creator>
		<pubDate>Sat, 02 Jan 2010 23:25:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/09/15/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/#comment-285</guid>
		<description>Thanks Darren. I had noticed the traffic. I&#039;ve applied to join the group and will attempt to contribute to the discussion. That being said I&#039;m just about to head out on a business trip so my time may be limited in the very near future.</description>
		<content:encoded><![CDATA[<p>Thanks Darren. I had noticed the traffic. I&#39;ve applied to join the group and will attempt to contribute to the discussion. That being said I&#39;m just about to head out on a business trip so my time may be limited in the very near future.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darren</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/09/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/comment-page-1/#comment-284</link>
		<dc:creator>Darren</dc:creator>
		<pubDate>Sat, 02 Jan 2010 19:36:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/09/15/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/#comment-284</guid>
		<description>I just thought I would point out a discussion about the original 2000 article currently generating a lot of traffic in the &quot;Real-Time Embedded Engineering&quot; group on LinkedIn. I can&#039;t see a static link so here is a link to the &lt;a href=&quot;http://www.linkedin.com/groups?home=&amp;gid=102939&amp;trk=anet_ug_hm&quot; rel=&quot;nofollow&quot;&gt;group&lt;/a&gt; and the &lt;a href=&quot;http://www.linkedin.com/e/ava/10603360/102939/EML_anet_qa_ttle-d7hOon0JumNFomgJt7dBpSBA/&quot; rel=&quot;nofollow&quot;&gt;discussion&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>I just thought I would point out a discussion about the original 2000 article currently generating a lot of traffic in the &quot;Real-Time Embedded Engineering&quot; group on LinkedIn. I can&#39;t see a static link so here is a link to the <a href="http://www.linkedin.com/groups?home=&amp;gid=102939&amp;trk=anet_ug_hm" rel="nofollow">group</a> and the <a href="http://www.linkedin.com/e/ava/10603360/102939/EML_anet_qa_ttle-d7hOon0JumNFomgJt7dBpSBA/" rel="nofollow">discussion</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: GregK</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/09/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/comment-page-1/#comment-283</link>
		<dc:creator>GregK</dc:creator>
		<pubDate>Mon, 21 Sep 2009 11:29:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/09/15/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/#comment-283</guid>
		<description>HiOf course I am not going use such technique at all. It is not resist critique. It is just an example. I just wanted to discuss, it is rather academic discussion if it proper place. Probably not :), we are focusing on practical approaching.Of course disaster is close, but is in programmer responsibility to use this technique proper, and compiler responsibility to compliant with standard.But I am actually not sure of this code:void generic_thread(void * parm){  volatile data_t p;  global_p = &p;  /* is it possible to optimise        and roll stack here?????????     I doubt it can. we reference      this variable below.      but better do not relay on it.  */  int tab[10];  for(;;) /* main loop */  {     sleep(1);     if (p.something)     {     }  }}//However volatile in functions is really useful for debugging purpose under high optimization level. Very often you can not see value of variable under debugger. volatile (just in debug compilation) is better then write to global variable, since global variable could be optimized even though is not static (good compilers and linkers can do this).</description>
		<content:encoded><![CDATA[<p>HiOf course I am not going use such technique at all. It is not resist critique. It is just an example. I just wanted to discuss, it is rather academic discussion if it proper place. Probably not <img src='http://embeddedgurus.com/stack-overflow/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , we are focusing on practical approaching.Of course disaster is close, but is in programmer responsibility to use this technique proper, and compiler responsibility to compliant with standard.But I am actually not sure of this code:void generic_thread(void * parm){  volatile data_t p;  global_p = &amp;p;  /* is it possible to optimise        and roll stack here?????????     I doubt it can. we reference      this variable below.      but better do not relay on it.  */  int tab[10];  for(;;) /* main loop */  {     sleep(1);     if (p.something)     {     }  }}//However volatile in functions is really useful for debugging purpose under high optimization level. Very often you can not see value of variable under debugger. volatile (just in debug compilation) is better then write to global variable, since global variable could be optimized even though is not static (good compilers and linkers can do this).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel Jones</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/09/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/comment-page-1/#comment-282</link>
		<dc:creator>Nigel Jones</dc:creator>
		<pubDate>Sun, 20 Sep 2009 13:49:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/09/15/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/#comment-282</guid>
		<description>GregK:To the best of my knowledge, the only variables allocated on the stack by a C compiler are function parameters and so called automatic variables (non statically allocated function variables declared at function scope). The key thing about these variables is that they have highly limited scope and also a highly limited lifetime. Now you can &lt;b&gt;always&lt;/b&gt; abuse such variables by taking their address and passing this address to other code to dereference. I predict disaster if you do though.Incidentally, the example you quoted sounds to me more like a case where memory would be allocated from the &lt;b&gt;heap&lt;/b&gt;.</description>
		<content:encoded><![CDATA[<p>GregK:To the best of my knowledge, the only variables allocated on the stack by a C compiler are function parameters and so called automatic variables (non statically allocated function variables declared at function scope). The key thing about these variables is that they have highly limited scope and also a highly limited lifetime. Now you can <b>always</b> abuse such variables by taking their address and passing this address to other code to dereference. I predict disaster if you do though.Incidentally, the example you quoted sounds to me more like a case where memory would be allocated from the <b>heap</b>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel Jones</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/09/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/comment-page-1/#comment-281</link>
		<dc:creator>Nigel Jones</dc:creator>
		<pubDate>Sun, 20 Sep 2009 13:42:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/09/15/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/#comment-281</guid>
		<description>Peter:You are correct about the scope of static. That being said, anyone that does this deserves what will inevitably happen the first time the code gets refactored. Indeed you can take this a step further. I think it was reader &#039;Uhmmmmmm&#039; that pointed out that one can indeed call a static function from another module (translation unit to be very precise), by simply calling it via a function pointer. Will this work? - sure, is it nuts? - yes.I find your statement about assembly language mostly true, but a strange justification for its use. (Note that I say this as someone who enjoys assembly language programming). For example, while it is in general true that with assembly language what you see is what you get,in my experience one soon starts resorting to higher level features in an assembler (such as parametrized macros, data structures, &#039;built-in&#039; functions etc), and that these are even more language specific than &#039;standard&#039; C.Now I am highly sympathetic to the use of assembly language for performance reasons. For example, I recently ranted about the lack of a 3 byte integer in most embedded C compilers that forces one to do perform operations on 4 byte integers when 3 bytes would do just fine. That being said, it&#039;s rare that I find myself in a CPU constrained situation, and so I find the need for assembly language to be diminishing. I might say that I think this is a bad thing, because until one has done assembly language programming, one can never really understand what is going on &#039;under the hood&#039;.</description>
		<content:encoded><![CDATA[<p>Peter:You are correct about the scope of static. That being said, anyone that does this deserves what will inevitably happen the first time the code gets refactored. Indeed you can take this a step further. I think it was reader &#39;Uhmmmmmm&#39; that pointed out that one can indeed call a static function from another module (translation unit to be very precise), by simply calling it via a function pointer. Will this work? &#8211; sure, is it nuts? &#8211; yes.I find your statement about assembly language mostly true, but a strange justification for its use. (Note that I say this as someone who enjoys assembly language programming). For example, while it is in general true that with assembly language what you see is what you get,in my experience one soon starts resorting to higher level features in an assembler (such as parametrized macros, data structures, &#39;built-in&#39; functions etc), and that these are even more language specific than &#39;standard&#39; C.Now I am highly sympathetic to the use of assembly language for performance reasons. For example, I recently ranted about the lack of a 3 byte integer in most embedded C compilers that forces one to do perform operations on 4 byte integers when 3 bytes would do just fine. That being said, it&#39;s rare that I find myself in a CPU constrained situation, and so I find the need for assembly language to be diminishing. I might say that I think this is a bad thing, because until one has done assembly language programming, one can never really understand what is going on &#39;under the hood&#39;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: GregK</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/09/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/comment-page-1/#comment-280</link>
		<dc:creator>GregK</dc:creator>
		<pubDate>Sun, 20 Sep 2009 10:40:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/09/15/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/#comment-280</guid>
		<description>HiNice job.I am thinking about other example to  question 0x8. your example b is:&quot;Non-stack variables referenced within an interrupt service routine.&quot;I think &quot;Non-stack&quot; is not appropriate. Memory allocated from stack do not differ specially than allocated during compile time. I am able image situation where thread allocate some memory on stack, pass pointer to this memory to IRQ, by global pointer, or signal from global queue. There are other methods, some RTOS using dispatcher to resolve/dispatch IRQ request, if so than routine can have argument or queue associated with IRQ to pass information. So IRQ eventually will using memory allocated from stack of other thread.What You think?</description>
		<content:encoded><![CDATA[<p>HiNice job.I am thinking about other example to  question 0&#215;8. your example b is:&quot;Non-stack variables referenced within an interrupt service routine.&quot;I think &quot;Non-stack&quot; is not appropriate. Memory allocated from stack do not differ specially than allocated during compile time. I am able image situation where thread allocate some memory on stack, pass pointer to this memory to IRQ, by global pointer, or signal from global queue. There are other methods, some RTOS using dispatcher to resolve/dispatch IRQ request, if so than routine can have argument or queue associated with IRQ to pass information. So IRQ eventually will using memory allocated from stack of other thread.What You think?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Butler</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/09/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/comment-page-1/#comment-279</link>
		<dc:creator>Peter Butler</dc:creator>
		<pubDate>Sat, 19 Sep 2009 21:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/09/15/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers-reprised/#comment-279</guid>
		<description>Your 0x10 best questions for would-be embedded programmers may overstate answer 6b.  You say, “A variable declared static within a module ... is accessible by all functions within that module.void f1(void) return ci+3;static int ci = 6;void f2(void) return ci+4;Will this compile?  I would expect that ci would be unknown to f1().  In my understanding const vs. #define is mostly a scope issue.Your 0x10 best questions ... is why I favor assembly code.  I KNOW what is going on.  No odd compiler or language strangeness.  But to be fair I use C/C++ as appropriate.  Consider fragments of code used to generate DTMF tones.  I used (ARM Cortex-M3) assembly code to form (signed int) 2^24*sin(x) where x is an unsigned 32-bit integer = r*(2^32)/(2*pi) and r is in radians.  I.e. x/(2^32) is the fraction of the way around a circle.  I wanted 12-bit accuracy (any more would be wasted) and I needed abs(sin(x)) &lt; 1.0 for all x.  Truncating the Taylor series at x^7/7! gave me both speed and the desired accuracy.Code calling my assembly code was in C.  I added appropriate constants to two variables, called my sin function twice and added the results.  The result went into a software FIFO which in retrospect likely should have been written in C.  The ISR playing the tone was in assembly.  It could have been written in C but any processor change (even a different vendors Cortex-M3) would require changes.  When it came time to write DTMF decode I used C and vendor-provided 32-bit software floating point.  This was WAY easier than implementing the Goertzel algorithm in 8051 assembly.</description>
		<content:encoded><![CDATA[<p>Your 0&#215;10 best questions for would-be embedded programmers may overstate answer 6b.  You say, “A variable declared static within a module &#8230; is accessible by all functions within that module.void f1(void) return ci+3;static int ci = 6;void f2(void) return ci+4;Will this compile?  I would expect that ci would be unknown to f1().  In my understanding const vs. #define is mostly a scope issue.Your 0&#215;10 best questions &#8230; is why I favor assembly code.  I KNOW what is going on.  No odd compiler or language strangeness.  But to be fair I use C/C++ as appropriate.  Consider fragments of code used to generate DTMF tones.  I used (ARM Cortex-M3) assembly code to form (signed int) 2^24*sin(x) where x is an unsigned 32-bit integer = r*(2^32)/(2*pi) and r is in radians.  I.e. x/(2^32) is the fraction of the way around a circle.  I wanted 12-bit accuracy (any more would be wasted) and I needed abs(sin(x)) &lt; 1.0 for all x.  Truncating the Taylor series at x^7/7! gave me both speed and the desired accuracy.Code calling my assembly code was in C.  I added appropriate constants to two variables, called my sin function twice and added the results.  The result went into a software FIFO which in retrospect likely should have been written in C.  The ISR playing the tone was in assembly.  It could have been written in C but any processor change (even a different vendors Cortex-M3) would require changes.  When it came time to write DTMF decode I used C and vendor-provided 32-bit software floating point.  This was WAY easier than implementing the Goertzel algorithm in 8051 assembly.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
