<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/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>what is the use of default in switch-case?</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/38040/what-is-the-use-of-default-in-switch-case</link><description> 
what is the use of default in switch-case? 
 </description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: what is the use of default in switch-case?</title><link>https://community.arm.com/thread/101208?ContentTypeID=1</link><pubDate>Sun, 19 Oct 2008 09:24:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f4055337-c765-4c75-b97b-cf6296b9ba55</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Entering the default clause in a state machine (where the switch
variable is normally an enumerator) should preferably be coded to
represent an error.&lt;/p&gt;

&lt;p&gt;
But a switch statement is used for way more than just state
machines.&lt;/p&gt;

&lt;p&gt;
When decoding charactesr in a parser, you may have:&lt;/p&gt;

&lt;pre&gt;
switch (ch) {
    case &amp;#39;(&amp;#39;: do_lparen(); break;
    case &amp;#39;)&amp;#39;: do_rparen(); break;
    case &amp;#39;+&amp;#39;: do_add(); break;
    ...
    default:
        if (ch &amp;gt;= &amp;#39;a&amp;#39; &amp;amp;&amp;amp; ch &amp;lt;= &amp;#39;z&amp;#39;
        ||  ch &amp;gt;= &amp;#39;A&amp;#39; &amp;amp;&amp;amp; ch &amp;lt;= &amp;#39;Z&amp;#39;) {
            do_alpha(ch);
        } else if (ch &amp;gt;= &amp;#39;0&amp;#39; &amp;amp;&amp;amp; ch &amp;lt;= &amp;#39;9&amp;#39;) {
            do_digit(ch);
        } else {
            invalid_character(ch);
        }
}
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: what is the use of default in switch-case?</title><link>https://community.arm.com/thread/89329?ContentTypeID=1</link><pubDate>Sun, 19 Oct 2008 06:47:04 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1ac26dfb-c435-4ad5-a9a9-a7ed04571cf6</guid><dc:creator>erik  malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
to catch coding mistakes&lt;br /&gt;
with few exceptions, if default: get entered you have made a
mistake&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: what is the use of default in switch-case?</title><link>https://community.arm.com/thread/52670?ContentTypeID=1</link><pubDate>Sun, 19 Oct 2008 03:46:43 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b16bbfa7-e117-4520-9101-d0944ccdb54f</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
It is similar to tht &amp;#39;else&amp;#39; in an &amp;#39;if&amp;#39; statement. Something to do
if no specific alternative matches.&lt;/p&gt;

&lt;p&gt;
Don&amp;#39;t you have a good C book to read? If not: Do get one!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>