<?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: Efficient C Tips #1 &#8211; Choosing the correct integer size</title>
	<atom:link href="http://embeddedgurus.com/stack-overflow/2008/06/efficient-c-tips-1-choosing-the-correct-integer-size/feed/" rel="self" type="application/rss+xml" />
	<link>http://embeddedgurus.com/stack-overflow/2008/06/efficient-c-tips-1-choosing-the-correct-integer-size/</link>
	<description>Thoughts on embedded systems by Nigel Jones</description>
	<lastBuildDate>Fri, 10 Feb 2012 14:37:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Anonymous</title>
		<link>http://embeddedgurus.com/stack-overflow/2008/06/efficient-c-tips-1-choosing-the-correct-integer-size/comment-page-1/#comment-1066</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Thu, 10 Jun 2010 10:42:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2008/06/15/efficient-c-tips-1-choosing-the-correct-integer-size/#comment-1066</guid>
		<description>The engineer who modified the hard coded constant should have been checking for side affects... however.

The original cautions engineer probably would have written in the first place:


// In some header file...
#define MY_VALUE 3000  // It was 100. But i need more!

...

int main()
{
  uint_fast8_t i;
  
  // Pre condition
  #if MY_VALUE &gt; UINT_FAST8_MAX
    #error &quot;Houston, we have a problem.&quot;
  #endif
    
  for (i = 0; i &lt; MY_VALUE; ++i) {
    ...
  }
  return 0;
}</description>
		<content:encoded><![CDATA[<p>The engineer who modified the hard coded constant should have been checking for side affects&#8230; however.</p>
<p>The original cautions engineer probably would have written in the first place:</p>
<p>// In some header file&#8230;<br />
#define MY_VALUE 3000  // It was 100. But i need more!</p>
<p>&#8230;</p>
<p>int main()<br />
{<br />
  uint_fast8_t i;</p>
<p>  // Pre condition<br />
  #if MY_VALUE &gt; UINT_FAST8_MAX<br />
    #error &#8220;Houston, we have a problem.&#8221;<br />
  #endif</p>
<p>  for (i = 0; i &lt; MY_VALUE; ++i) {<br />
    &#8230;<br />
  }<br />
  return 0;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Granade</title>
		<link>http://embeddedgurus.com/stack-overflow/2008/06/efficient-c-tips-1-choosing-the-correct-integer-size/comment-page-1/#comment-1051</link>
		<dc:creator>Kevin Granade</dc:creator>
		<pubDate>Wed, 02 Jun 2010 16:34:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2008/06/15/efficient-c-tips-1-choosing-the-correct-integer-size/#comment-1051</guid>
		<description>One problem with this is that if you are targeting multiple platforms, it may compile on some and not on others at that point.  You&#039;ve asked for &quot;at least 8 bits&quot;, will it generate a warning or error on a given architecture even if uint_fast8_t is actually 16 bits?  I&#039;m pretty sure it wouldn&#039;t, as the definition of uint_fast8_t on my system is &quot;typedef unsigned char uint_fast8_t;&quot;.  If it happened to be a 16 bit variable instead, it would do bounds checking against a 16 bit variable, so could miss the constraint violation.

Regardless, with gcc the following code did not generate an error or warning, and performed as expected, infinite loop:

#include 

int main()
{
   uint_fast8_t i;

   for(i = 0; i &lt; 3000; ++i)
   {
      ;
   }
   return 0;
}</description>
		<content:encoded><![CDATA[<p>One problem with this is that if you are targeting multiple platforms, it may compile on some and not on others at that point.  You&#8217;ve asked for &#8220;at least 8 bits&#8221;, will it generate a warning or error on a given architecture even if uint_fast8_t is actually 16 bits?  I&#8217;m pretty sure it wouldn&#8217;t, as the definition of uint_fast8_t on my system is &#8220;typedef unsigned char uint_fast8_t;&#8221;.  If it happened to be a 16 bit variable instead, it would do bounds checking against a 16 bit variable, so could miss the constraint violation.</p>
<p>Regardless, with gcc the following code did not generate an error or warning, and performed as expected, infinite loop:</p>
<p>#include </p>
<p>int main()<br />
{<br />
   uint_fast8_t i;</p>
<p>   for(i = 0; i &lt; 3000; ++i)<br />
   {<br />
      ;<br />
   }<br />
   return 0;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles</title>
		<link>http://embeddedgurus.com/stack-overflow/2008/06/efficient-c-tips-1-choosing-the-correct-integer-size/comment-page-1/#comment-677</link>
		<dc:creator>Charles</dc:creator>
		<pubDate>Sun, 11 Apr 2010 01:52:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2008/06/15/efficient-c-tips-1-choosing-the-correct-integer-size/#comment-677</guid>
		<description>With 256 bytes, I&#039;d go back to assembly
Like Nigel, I started with assembly and very little memory available and it was great fun; now our processors have evolved and our code base supports  3 (cached!) architectures, I find it ugly!
What I found more difficult when writing assembly was very often we were hitting non documented bugs of the processor and had to resort to NOP insertion after lengthy discussion with architecture team (&quot;it&#039;s the software!&quot;, &quot;it&#039;s the hardware!&quot;)</description>
		<content:encoded><![CDATA[<p>With 256 bytes, I&#8217;d go back to assembly<br />
Like Nigel, I started with assembly and very little memory available and it was great fun; now our processors have evolved and our code base supports  3 (cached!) architectures, I find it ugly!<br />
What I found more difficult when writing assembly was very often we were hitting non documented bugs of the processor and had to resort to NOP insertion after lengthy discussion with architecture team (&#8220;it&#8217;s the software!&#8221;, &#8220;it&#8217;s the hardware!&#8221;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles</title>
		<link>http://embeddedgurus.com/stack-overflow/2008/06/efficient-c-tips-1-choosing-the-correct-integer-size/comment-page-1/#comment-676</link>
		<dc:creator>Charles</dc:creator>
		<pubDate>Sun, 11 Apr 2010 01:45:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2008/06/15/efficient-c-tips-1-choosing-the-correct-integer-size/#comment-676</guid>
		<description>I would think the compiler should be able to generate a warning:
 we would be testing a variable of 8bit width against an out of bound constant
shouldn&#039;t it?</description>
		<content:encoded><![CDATA[<p>I would think the compiler should be able to generate a warning:<br />
 we would be testing a variable of 8bit width against an out of bound constant<br />
shouldn&#8217;t it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel Jones</title>
		<link>http://embeddedgurus.com/stack-overflow/2008/06/efficient-c-tips-1-choosing-the-correct-integer-size/comment-page-1/#comment-45</link>
		<dc:creator>Nigel Jones</dc:creator>
		<pubDate>Wed, 24 Feb 2010 19:29:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2008/06/15/efficient-c-tips-1-choosing-the-correct-integer-size/#comment-45</guid>
		<description>I couldn&#039;t agree more. Not withstanding the issues you&#039;ve raised, IMHO not using the optimizer leaves you vulnerable to not finding mistakes such as failing to declare appropriate variables as volatile, failure to notice that certain code is useless etc.</description>
		<content:encoded><![CDATA[<p>I couldn&#39;t agree more. Not withstanding the issues you&#39;ve raised, IMHO not using the optimizer leaves you vulnerable to not finding mistakes such as failing to declare appropriate variables as volatile, failure to notice that certain code is useless etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Nelson</title>
		<link>http://embeddedgurus.com/stack-overflow/2008/06/efficient-c-tips-1-choosing-the-correct-integer-size/comment-page-1/#comment-44</link>
		<dc:creator>Greg Nelson</dc:creator>
		<pubDate>Wed, 24 Feb 2010 19:14:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2008/06/15/efficient-c-tips-1-choosing-the-correct-integer-size/#comment-44</guid>
		<description>Steve Karg said (basically): &quot;Extreme Programming teaches you &#039;don&#039;t optimize.&#039;&quot;In my opinion, this simply proves that Extreme Programming is for C# programmers on 64-bit 3GHz windows boxes with infinite swap space.In one of my most recent programs, I had to build my own version of &quot;printf(&quot;%02d&quot;)&quot; because the call to printf made my application no longer fit into the 256 bytes of available RAM.  &quot;Don&#039;t optimize&quot; under these circumstances equates to &quot;don&#039;t get the job done.&quot;  Not an option.</description>
		<content:encoded><![CDATA[<p>Steve Karg said (basically): &quot;Extreme Programming teaches you &#39;don&#39;t optimize.&#39;&quot;In my opinion, this simply proves that Extreme Programming is for C# programmers on 64-bit 3GHz windows boxes with infinite swap space.In one of my most recent programs, I had to build my own version of &quot;printf(&quot;%02d&quot;)&quot; because the call to printf made my application no longer fit into the 256 bytes of available RAM.  &quot;Don&#39;t optimize&quot; under these circumstances equates to &quot;don&#39;t get the job done.&quot;  Not an option.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve Karg</title>
		<link>http://embeddedgurus.com/stack-overflow/2008/06/efficient-c-tips-1-choosing-the-correct-integer-size/comment-page-1/#comment-43</link>
		<dc:creator>Steve Karg</dc:creator>
		<pubDate>Wed, 03 Feb 2010 17:40:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2008/06/15/efficient-c-tips-1-choosing-the-correct-integer-size/#comment-43</guid>
		<description>ashleigh: for my portable code using C99 standard integers, I try not to litter my code with #if&#039;s, but instead just have a ports/xx directory that includes a stdint.h for the compiler that is lacking C99 support for standard integers.Nigel: as for using fast/least standard integers in a project, I have I have two rules about &lt;a href=&quot;http://cisx2.uma.maine.edu/NickTemp/JSP&amp;JSDLec/jsd.html&quot; rel=&quot;nofollow&quot;&gt;optimizing&lt;/a&gt; that I learned while studying Extreme Programming:Rule 1: Don&#039;t do it.Rule 2: (for experts only). Don&#039;t do it yet - that is, not until you have a perfectly clear and unoptimized solution.</description>
		<content:encoded><![CDATA[<p>ashleigh: for my portable code using C99 standard integers, I try not to litter my code with #if&#39;s, but instead just have a ports/xx directory that includes a stdint.h for the compiler that is lacking C99 support for standard integers.Nigel: as for using fast/least standard integers in a project, I have I have two rules about <a href="http://cisx2.uma.maine.edu/NickTemp/JSP&amp;JSDLec/jsd.html" rel="nofollow">optimizing</a> that I learned while studying Extreme Programming:Rule 1: Don&#39;t do it.Rule 2: (for experts only). Don&#39;t do it yet &#8211; that is, not until you have a perfectly clear and unoptimized solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://embeddedgurus.com/stack-overflow/2008/06/efficient-c-tips-1-choosing-the-correct-integer-size/comment-page-1/#comment-42</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Thu, 28 Jan 2010 16:21:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2008/06/15/efficient-c-tips-1-choosing-the-correct-integer-size/#comment-42</guid>
		<description>&quot;Indeed they do. The sooner that everyone starts using the C99 syntax the better IMHO.1/25/2010 2:33 PM&quot;Nigel, I understand your enthusiasm, but C99 was adopted in 2000, your comment is about 10 years later - perhaps it&#039;s time to think of why everyone hasn&#039;t started using it and get back to coding.JW</description>
		<content:encoded><![CDATA[<p>&quot;Indeed they do. The sooner that everyone starts using the C99 syntax the better IMHO.1/25/2010 2:33 PM&quot;Nigel, I understand your enthusiasm, but C99 was adopted in 2000, your comment is about 10 years later &#8211; perhaps it&#39;s time to think of why everyone hasn&#39;t started using it and get back to coding.JW</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel Jones</title>
		<link>http://embeddedgurus.com/stack-overflow/2008/06/efficient-c-tips-1-choosing-the-correct-integer-size/comment-page-1/#comment-41</link>
		<dc:creator>Nigel Jones</dc:creator>
		<pubDate>Thu, 28 Jan 2010 11:52:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2008/06/15/efficient-c-tips-1-choosing-the-correct-integer-size/#comment-41</guid>
		<description>Mike - I like your observation. It is indeed a weakness of these C99 data types that I had not previously considered.</description>
		<content:encoded><![CDATA[<p>Mike &#8211; I like your observation. It is indeed a weakness of these C99 data types that I had not previously considered.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://embeddedgurus.com/stack-overflow/2008/06/efficient-c-tips-1-choosing-the-correct-integer-size/comment-page-1/#comment-40</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 26 Jan 2010 09:03:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2008/06/15/efficient-c-tips-1-choosing-the-correct-integer-size/#comment-40</guid>
		<description>One thing overlooked in this enthusiasm for C99 is code validation:  Let&#039;s say the compiler uses a two byte native operand for the &quot;fast&quot; type in the example.  And lets say someone comes back and creates a bug by extended the loop limit to 300.  Maybe the compiler notices this and generates a warning based on the compare, but probably it doesn&#039;t.  And the code tests great.  So now we think the code is solid.  But, of course, it breaks as soon as we port it to &quot;fast is 8 bits&quot;--possibly in a non-obvious way.Mike Layton</description>
		<content:encoded><![CDATA[<p>One thing overlooked in this enthusiasm for C99 is code validation:  Let&#39;s say the compiler uses a two byte native operand for the &quot;fast&quot; type in the example.  And lets say someone comes back and creates a bug by extended the loop limit to 300.  Maybe the compiler notices this and generates a warning based on the compare, but probably it doesn&#39;t.  And the code tests great.  So now we think the code is solid.  But, of course, it breaks as soon as we port it to &quot;fast is 8 bits&quot;&#8211;possibly in a non-obvious way.Mike Layton</p>
]]></content:encoded>
	</item>
</channel>
</rss>

