<?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/">
	<channel>
		<title><![CDATA[MISRA Discussion Forums - 8.15 Control flow]]></title>
		<link>https://forum.misra.org.uk/</link>
		<description><![CDATA[MISRA Discussion Forums - https://forum.misra.org.uk]]></description>
		<pubDate>Thu, 05 Nov 2026 15:13:39 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[Rule 15.5 and return statements as children of labels]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1485</link>
			<pubDate>Fri, 29 Mar 2019 13:33:29 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=318">rgamble</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1485</guid>
			<description><![CDATA[Rule 15.5 says:<br />
<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>When a return statement is used, it should be the final statement in the compound statement that forms the body of the function.</blockquote>
<br />
Consider the following example:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef unsigned uint32_t;<br />
uint32_t ten(uint32_t var) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (var == 10) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 10;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
I think it is pretty clear that this violates Rule 15.5 as the <span style="font-weight: bold;" class="mycode_b">return</span> statement is a child statement of the body of the <span style="font-weight: bold;" class="mycode_b">if</span>, even though no other statements appear between the <span style="font-weight: bold;" class="mycode_b">return</span> statement and the end of the function.  Is this correct?<br />
<br />
What then about the following:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef unsigned uint32_t;<br />
uint32_t ten() {<br />
my_label:<br />
&nbsp;&nbsp;&nbsp;&nbsp;return 10;<br />
}</code></div></div><br />
The return statement is technically a child of the label statement so the "final statement in the compound statement that forms the body of the function" is a label statement according to the grammar of C.  Is this intended to be a violation of Rule 15.5?]]></description>
			<content:encoded><![CDATA[Rule 15.5 says:<br />
<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>When a return statement is used, it should be the final statement in the compound statement that forms the body of the function.</blockquote>
<br />
Consider the following example:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef unsigned uint32_t;<br />
uint32_t ten(uint32_t var) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (var == 10) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 10;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
I think it is pretty clear that this violates Rule 15.5 as the <span style="font-weight: bold;" class="mycode_b">return</span> statement is a child statement of the body of the <span style="font-weight: bold;" class="mycode_b">if</span>, even though no other statements appear between the <span style="font-weight: bold;" class="mycode_b">return</span> statement and the end of the function.  Is this correct?<br />
<br />
What then about the following:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef unsigned uint32_t;<br />
uint32_t ten() {<br />
my_label:<br />
&nbsp;&nbsp;&nbsp;&nbsp;return 10;<br />
}</code></div></div><br />
The return statement is technically a child of the label statement so the "final statement in the compound statement that forms the body of the function" is a label statement according to the grammar of C.  Is this intended to be a violation of Rule 15.5?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 15.7 and empty else statements without "else if"]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1381</link>
			<pubDate>Tue, 17 Oct 2017 13:36:52 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=318">rgamble</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1381</guid>
			<description><![CDATA[MISRA C 2012 Rule 15.7 states in the amplification that "The else statement shall contain at least either one side effect or a<br />
comment."  Does "The else statement" refers to <span style="font-style: italic;" class="mycode_i">any</span> else statement or just the final else statement that is required<br />
by the rule when there are one or more "else if" statements?  Is the following example a violation of Rule 15.7 because the else<br />
statement does not contain a side effect or comment or is it compliant because the else is not required by the rule?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef _Bool bool_t;<br />
void foo(bool_t x); <br />
void foo(bool_t x) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (x) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;else { } <br />
}</code></div></div>]]></description>
			<content:encoded><![CDATA[MISRA C 2012 Rule 15.7 states in the amplification that "The else statement shall contain at least either one side effect or a<br />
comment."  Does "The else statement" refers to <span style="font-style: italic;" class="mycode_i">any</span> else statement or just the final else statement that is required<br />
by the rule when there are one or more "else if" statements?  Is the following example a violation of Rule 15.7 because the else<br />
statement does not contain a side effect or comment or is it compliant because the else is not required by the rule?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef _Bool bool_t;<br />
void foo(bool_t x); <br />
void foo(bool_t x) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (x) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;else { } <br />
}</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 15.7, 16.4, side-effects and statements.]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1330</link>
			<pubDate>Tue, 04 Apr 2017 12:04:30 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4406">RichardC</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1330</guid>
			<description><![CDATA[Rule 15.7 "if...else if terminated by else" refers to "Rule 16.5".  However, there appears to be a stronger relationship with 16.4: "Every switch shall have a default label".  Should 16.4 be linked to 15.7?<br />
<br />
In my opinion, there is a slight inconsistency between the rule rationale for 15.7 and 16.4 and what might be read as being covered.<br />
<br />
Starting with Rule 15.7, the amplification requires a side-effect or a comment.  Would you agree that this interpretation results in the following examples being 'non-compliant'?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f1 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; 10; ++i)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i % x )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if (i % y)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Non-Compliant? Not a side-effect and not a comment */<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void f2 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (x != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else if (y != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* Non-Compliant? Not a side-effect and not a comment.<br />
&nbsp;&nbsp;&nbsp;&nbsp; * Non-compliant to advisory 15.5 */<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void f3 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (x != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else if (y != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* Non-Compliant? Not a side-effect and not a comment. */<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void f4 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (x != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else if (y != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;goto END;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* Non-Compliant? Not a side-effect and not a comment. */<br />
<br />
&nbsp;&nbsp;END:<br />
&nbsp;&nbsp;&nbsp;&nbsp;;<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void f5 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; 10; ++i)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i % x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if (i % y)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i != x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i != y)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ((i*i) &gt; (x*y))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Non-Compliant? No comment or side-effect */<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}</code></div></div><br />
And the following examples would be compliant:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f6 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (x != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else if (y != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant */<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void f7 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (x != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else if (y != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant, but Non-Compliant with 15.6 */ ;<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void f8 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; 10; ++i)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i % x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if (i % y)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i != x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i != y)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ((i*i) &gt; (x*y))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant? Comment "appears" in else. */<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}</code></div></div><br />
For Rule 16.4, the amplification requires a 'statement'.  What do you feel is that status of the following examples?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f9 (int x)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;switch (x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 0:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 3:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=3;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;default:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant? Is ';' a statement? */<br />
<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void fA (int x)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;switch (x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 0:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 3:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=3;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;default:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant? Depends on interpretation of 16.1 regarding { } is a compound statement */<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void fB (int x)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;switch (x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 0:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 3:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=3;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;default:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ { } }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant? Similar to fA */<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void fC (int x)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;switch (x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 0:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 3:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=3;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;default:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant */<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}</code></div></div><br />
My reading of the Rationale is that the goal is have a 'defensive' comment unless the else does something, ie. the comment acts as a form of "Annotation".<br />
<br />
<br />
Alternatively, going just from the rationale, I would mark the above functions as Compliant/Non-Compliant as follows:<br />
<ul class="mycode_list"><li>f1: Compliant<br />
</li>
<li>f2: Compliant, Non-Compliant with rule 15.5.<br />
</li>
<li>f3: Non-Compliant<br />
</li>
<li>f4: Compliant<br />
</li>
<li>f5: Compliant<br />
</li>
<li>f6: Compliant<br />
</li>
<li>f7: Compliant, Non-Compliant with Rule 15.6<br />
</li>
<li>f8: Compliant (not because of nested comment)<br />
</li>
<li>f9: Non-Compliant<br />
</li>
<li>fA: Non-Compliant<br />
</li>
<li>fB: Compliant</li>
</ul>
<br />
What is the view of the MISRA C group on this?]]></description>
			<content:encoded><![CDATA[Rule 15.7 "if...else if terminated by else" refers to "Rule 16.5".  However, there appears to be a stronger relationship with 16.4: "Every switch shall have a default label".  Should 16.4 be linked to 15.7?<br />
<br />
In my opinion, there is a slight inconsistency between the rule rationale for 15.7 and 16.4 and what might be read as being covered.<br />
<br />
Starting with Rule 15.7, the amplification requires a side-effect or a comment.  Would you agree that this interpretation results in the following examples being 'non-compliant'?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f1 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; 10; ++i)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i % x )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if (i % y)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Non-Compliant? Not a side-effect and not a comment */<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void f2 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (x != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else if (y != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* Non-Compliant? Not a side-effect and not a comment.<br />
&nbsp;&nbsp;&nbsp;&nbsp; * Non-compliant to advisory 15.5 */<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void f3 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (x != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else if (y != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* Non-Compliant? Not a side-effect and not a comment. */<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void f4 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (x != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else if (y != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;goto END;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* Non-Compliant? Not a side-effect and not a comment. */<br />
<br />
&nbsp;&nbsp;END:<br />
&nbsp;&nbsp;&nbsp;&nbsp;;<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void f5 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; 10; ++i)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i % x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if (i % y)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i != x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i != y)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ((i*i) &gt; (x*y))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Non-Compliant? No comment or side-effect */<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}</code></div></div><br />
And the following examples would be compliant:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f6 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (x != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else if (y != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant */<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void f7 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (x != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else if (y != 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant, but Non-Compliant with 15.6 */ ;<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void f8 (int x, int y)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; 10; ++i)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i % x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if (i % y)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i != x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i != y)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ((i*i) &gt; (x*y))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant? Comment "appears" in else. */<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}</code></div></div><br />
For Rule 16.4, the amplification requires a 'statement'.  What do you feel is that status of the following examples?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f9 (int x)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;switch (x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 0:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 3:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=3;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;default:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant? Is ';' a statement? */<br />
<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void fA (int x)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;switch (x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 0:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 3:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=3;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;default:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant? Depends on interpretation of 16.1 regarding { } is a compound statement */<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void fB (int x)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;switch (x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 0:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 3:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=3;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;default:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ { } }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant? Similar to fA */<br />
&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;void fC (int x)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;switch (x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 0:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 3:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x+=3;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;default:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant */<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}</code></div></div><br />
My reading of the Rationale is that the goal is have a 'defensive' comment unless the else does something, ie. the comment acts as a form of "Annotation".<br />
<br />
<br />
Alternatively, going just from the rationale, I would mark the above functions as Compliant/Non-Compliant as follows:<br />
<ul class="mycode_list"><li>f1: Compliant<br />
</li>
<li>f2: Compliant, Non-Compliant with rule 15.5.<br />
</li>
<li>f3: Non-Compliant<br />
</li>
<li>f4: Compliant<br />
</li>
<li>f5: Compliant<br />
</li>
<li>f6: Compliant<br />
</li>
<li>f7: Compliant, Non-Compliant with Rule 15.6<br />
</li>
<li>f8: Compliant (not because of nested comment)<br />
</li>
<li>f9: Non-Compliant<br />
</li>
<li>fA: Non-Compliant<br />
</li>
<li>fB: Compliant</li>
</ul>
<br />
What is the view of the MISRA C group on this?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[15.7 and side effects]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1217</link>
			<pubDate>Fri, 11 Dec 2015 00:08:34 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=1443">lovewar</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1217</guid>
			<description><![CDATA[Would the following examples be compliant with rule #15.7?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void R_15_7 ( void ) {<br />
&nbsp;&nbsp; bool_t flag_1 = get_bool ( );<br />
&nbsp;&nbsp; bool_t flag_2 = get_bool ( );<br />
&nbsp;&nbsp; if ( flag_1 )&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action_f1 ( );<br />
&nbsp;&nbsp; }<br />
&nbsp;&nbsp; else if ( flag_2 )&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action_f2 ( );<br />
&nbsp;&nbsp; }<br />
&nbsp;&nbsp; else {&nbsp;&nbsp;// here , is the "else" compliant ?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;persistent_side_effects();<br />
&nbsp;&nbsp;}<br />
}</code></div></div><br />
Would the following examples be compliant with rule #15.7?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void R_15_7 ( void ) {<br />
&nbsp;&nbsp; bool_t flag_1 = get_bool ( );<br />
&nbsp;&nbsp; bool_t flag_2 = get_bool ( );<br />
&nbsp;&nbsp; if ( flag_1 )&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action_f1 ( );<br />
&nbsp;&nbsp; }<br />
&nbsp;&nbsp; else if ( flag_2 )&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action_f2 ( );<br />
&nbsp;&nbsp; }<br />
&nbsp;&nbsp; else {&nbsp;&nbsp;// here , is the "else" compliant ?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;side_effects();<br />
&nbsp;&nbsp;}<br />
}</code></div></div><br />
Would the following examples be non-compliant with rule #15.7?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void R_15_7 ( void ) {<br />
&nbsp;&nbsp; bool_t flag_1 = get_bool ( );<br />
&nbsp;&nbsp; bool_t flag_2 = get_bool ( );<br />
&nbsp;&nbsp; if ( flag_1 )&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action_f1 ( );<br />
&nbsp;&nbsp; }<br />
&nbsp;&nbsp; else if ( flag_2 )&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action_f2 ( );<br />
&nbsp;&nbsp; }<br />
&nbsp;&nbsp; else {&nbsp;&nbsp;// here, is the "else" non-compliant ?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;no_side_effects();<br />
&nbsp;&nbsp;}<br />
}</code></div></div>]]></description>
			<content:encoded><![CDATA[Would the following examples be compliant with rule #15.7?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void R_15_7 ( void ) {<br />
&nbsp;&nbsp; bool_t flag_1 = get_bool ( );<br />
&nbsp;&nbsp; bool_t flag_2 = get_bool ( );<br />
&nbsp;&nbsp; if ( flag_1 )&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action_f1 ( );<br />
&nbsp;&nbsp; }<br />
&nbsp;&nbsp; else if ( flag_2 )&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action_f2 ( );<br />
&nbsp;&nbsp; }<br />
&nbsp;&nbsp; else {&nbsp;&nbsp;// here , is the "else" compliant ?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;persistent_side_effects();<br />
&nbsp;&nbsp;}<br />
}</code></div></div><br />
Would the following examples be compliant with rule #15.7?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void R_15_7 ( void ) {<br />
&nbsp;&nbsp; bool_t flag_1 = get_bool ( );<br />
&nbsp;&nbsp; bool_t flag_2 = get_bool ( );<br />
&nbsp;&nbsp; if ( flag_1 )&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action_f1 ( );<br />
&nbsp;&nbsp; }<br />
&nbsp;&nbsp; else if ( flag_2 )&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action_f2 ( );<br />
&nbsp;&nbsp; }<br />
&nbsp;&nbsp; else {&nbsp;&nbsp;// here , is the "else" compliant ?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;side_effects();<br />
&nbsp;&nbsp;}<br />
}</code></div></div><br />
Would the following examples be non-compliant with rule #15.7?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void R_15_7 ( void ) {<br />
&nbsp;&nbsp; bool_t flag_1 = get_bool ( );<br />
&nbsp;&nbsp; bool_t flag_2 = get_bool ( );<br />
&nbsp;&nbsp; if ( flag_1 )&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action_f1 ( );<br />
&nbsp;&nbsp; }<br />
&nbsp;&nbsp; else if ( flag_2 )&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action_f2 ( );<br />
&nbsp;&nbsp; }<br />
&nbsp;&nbsp; else {&nbsp;&nbsp;// here, is the "else" non-compliant ?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;no_side_effects();<br />
&nbsp;&nbsp;}<br />
}</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 15.5]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1098</link>
			<pubDate>Wed, 13 Aug 2014 10:13:47 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=3483">Mandar_Pitale</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1098</guid>
			<description><![CDATA[Rule 15.5 is "A function should have a single point of exit at the end".<br />
<br />
The Rationale of this rule says:<br />
<br />
Early returns may lead to the unintentional omission of function termination code.<br />
<br />
1. What is "function termination code" in this context? Does it mean user defined C statements of the function or the function epilogue after the compilation? <br />
<br />
2. If it is the function epilogue, then does it mean that when multiple exit points are used, then it MAY result in imbalanced context retrieval when the function returns, for some compilers?]]></description>
			<content:encoded><![CDATA[Rule 15.5 is "A function should have a single point of exit at the end".<br />
<br />
The Rationale of this rule says:<br />
<br />
Early returns may lead to the unintentional omission of function termination code.<br />
<br />
1. What is "function termination code" in this context? Does it mean user defined C statements of the function or the function epilogue after the compilation? <br />
<br />
2. If it is the function epilogue, then does it mean that when multiple exit points are used, then it MAY result in imbalanced context retrieval when the function returns, for some compilers?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 15.3 Example]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1021</link>
			<pubDate>Tue, 21 Jan 2014 10:09:59 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=114">ogawa.kiyoshi</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1021</guid>
			<description><![CDATA[Rule 15.3  Example<br />
void f1(int32_t a){<br />
	if ( a 0){<br />
	  L2:<br />
		;<br />
	}<br />
}<br />
has some unreachable codes. So I think<br />
void f1(int32_t a){<br />
	if ( a 0){<br />
	  L2:<br />
		;<br />
	}<br />
}<br />
are enough and no unreachable codes.<br />
<br />
Dr. Ogawa Kiyoshi<br />
<a href="https://twitter.com/kaizen_nagoya/" target="_blank" rel="noopener" class="mycode_url">https://twitter.com/kaizen_nagoya/</a>, <a href="http://researchmap.jp/kaizen/MISRA-C/" target="_blank" rel="noopener" class="mycode_url">http://researchmap.jp/kaizen/MISRA-C/</a>]]></description>
			<content:encoded><![CDATA[Rule 15.3  Example<br />
void f1(int32_t a){<br />
	if ( a 0){<br />
	  L2:<br />
		;<br />
	}<br />
}<br />
has some unreachable codes. So I think<br />
void f1(int32_t a){<br />
	if ( a 0){<br />
	  L2:<br />
		;<br />
	}<br />
}<br />
are enough and no unreachable codes.<br />
<br />
Dr. Ogawa Kiyoshi<br />
<a href="https://twitter.com/kaizen_nagoya/" target="_blank" rel="noopener" class="mycode_url">https://twitter.com/kaizen_nagoya/</a>, <a href="http://researchmap.jp/kaizen/MISRA-C/" target="_blank" rel="noopener" class="mycode_url">http://researchmap.jp/kaizen/MISRA-C/</a>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 15.3, switch's, and "fallthru"]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1002</link>
			<pubDate>Tue, 10 Dec 2013 16:59:28 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=64">gs</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1002</guid>
			<description><![CDATA[Rule 15.3 states, "For the purposes of this rule, a switch-clause that does not consist of a compound statement is treated as if it were a block." What if the switch-clause did not end in an unconditional "break;"? While I understand such code would violate other rule(s), the point raised remains: would the following code violate <span style="font-style: italic;" class="mycode_i">this</span> rule?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>...<br />
switch( a )<br />
{<br />
case 1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;if( f(a) &gt; 8 )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;goto b;<br />
&nbsp;&nbsp;&nbsp;&nbsp;doingSomething();<br />
case 2:<br />
&nbsp;&nbsp;&nbsp;&nbsp;doingSomeOtherThing();<br />
b:<br />
&nbsp;&nbsp;&nbsp;&nbsp;tada( a );<br />
&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
default:<br />
&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
}<br />
...</code></div></div>]]></description>
			<content:encoded><![CDATA[Rule 15.3 states, "For the purposes of this rule, a switch-clause that does not consist of a compound statement is treated as if it were a block." What if the switch-clause did not end in an unconditional "break;"? While I understand such code would violate other rule(s), the point raised remains: would the following code violate <span style="font-style: italic;" class="mycode_i">this</span> rule?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>...<br />
switch( a )<br />
{<br />
case 1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;if( f(a) &gt; 8 )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;goto b;<br />
&nbsp;&nbsp;&nbsp;&nbsp;doingSomething();<br />
case 2:<br />
&nbsp;&nbsp;&nbsp;&nbsp;doingSomeOtherThing();<br />
b:<br />
&nbsp;&nbsp;&nbsp;&nbsp;tada( a );<br />
&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
default:<br />
&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
}<br />
...</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Does rule #15.3 apply to all blocks or only control blocks?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=956</link>
			<pubDate>Tue, 09 Apr 2013 14:49:57 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=64">gs</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=956</guid>
			<description><![CDATA[Suppose I have the following code:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;goto L1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
L1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
Does this code violate rule #15.3?]]></description>
			<content:encoded><![CDATA[Suppose I have the following code:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;goto L1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
L1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
Does this code violate rule #15.3?]]></content:encoded>
		</item>
	</channel>
</rss>