<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>C switch statements</title><link>/members-area/personalblogs/b/blog/posts/c-switch-statements</link><description>This week I covered several approaches to make large switch statements execute faster and save power. Switch statements are a great way to help keep your code readable but it is easy to forget they can turn into a long sequence of if-then-else statem</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: C switch statements</title><link>https://community.element14.com/members-area/personalblogs/b/blog/posts/c-switch-statements</link><pubDate>Tue, 29 Oct 2013 17:42:07 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:c89889d2-5c7d-447c-92a1-f23d5ef43067</guid><dc:creator>michaelkellett</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;@Mike,&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Do you have any measured data to show the benefits of your design suggestions in terms of power reduction ?&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;My approach would be to write code which most clearly expresses (in my case in C, VHDL or Verilog) intent and in the first instance to let the tools do the optimisation. So if I was desperate to optimise power consumption I would start with a nice clear case statement (assuming that was the obvious way to code, using an enumerated type for the switch variable for safety and clarity). Then I would want to &lt;strong&gt;&lt;em&gt;measure&lt;/em&gt;&lt;/strong&gt; any benefit from changing from the best compiler optimisation to &amp;quot;power crafted&amp;quot; code.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;MK&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=16886&amp;AppID=293&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: C switch statements</title><link>https://community.element14.com/members-area/personalblogs/b/blog/posts/c-switch-statements</link><pubDate>Thu, 24 Oct 2013 20:08:34 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:c89889d2-5c7d-447c-92a1-f23d5ef43067</guid><dc:creator>DAB</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Hi Mike,&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;I should temper your enthusiasm a little.&lt;/p&gt;&lt;p&gt;Large Switch statement lists often lead to a world of reliablity issues.&lt;/p&gt;&lt;p&gt;When you calculate the probability of error, the Switch statement leads to more software defects than any other single Software statement.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;So yes they are useful, but they are also dangerous if you do not build up a solid decision tree around them to reduce the possibility for errors in your code.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;DAB&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=16886&amp;AppID=293&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>