<?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.13 Side effects]]></title>
		<link>https://forum.misra.org.uk/</link>
		<description><![CDATA[MISRA Discussion Forums - https://forum.misra.org.uk]]></description>
		<pubDate>Wed, 25 Nov 2026 03:52:30 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[13.3 Should side effects be allowed in comma expressions?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1781</link>
			<pubDate>Mon, 31 Aug 2026 12:52:23 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6753">Loïc</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1781</guid>
			<description><![CDATA[In a comma expression (which is discouraged by another advisory rule, 12.3, but could still be used), there is a clear separation in term of execution between what comes before and what comes after the comma. Therefore, I think the rationale is not very strong in this case.<br />
<br />
What would you think of relaxing 13.3 and making this example compliant (it would still be non-compliant with 12.3):<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>int f(int n, int*dest) {<br />
    for (int i = 0 ; i&lt;10 ; ++i, ++dest) { // Currently non-compliant<br />
        *dest = i*i;<br />
    }<br />
}</code></div></div>]]></description>
			<content:encoded><![CDATA[In a comma expression (which is discouraged by another advisory rule, 12.3, but could still be used), there is a clear separation in term of execution between what comes before and what comes after the comma. Therefore, I think the rationale is not very strong in this case.<br />
<br />
What would you think of relaxing 13.3 and making this example compliant (it would still be non-compliant with 12.3):<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>int f(int n, int*dest) {<br />
    for (int i = 0 ; i&lt;10 ; ++i, ++dest) { // Currently non-compliant<br />
        *dest = i*i;<br />
    }<br />
}</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[13.3 What not being evaluated means?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1780</link>
			<pubDate>Fri, 28 Aug 2026 16:19:16 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6753">Loïc</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1780</guid>
			<description><![CDATA[Hi there,<br />
<br />
Rule 13.3 says:<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>All sub-expressions of the <span style="font-style: italic;" class="mycode_i">full expression</span> are treated as if they were evaluated for the purposes of this rule, even if specified as not being evaluated by the C Standard.</blockquote>
<br />
I understand what it makes sense in the context for instance of the conditional operator, but I wanted to check it this applies the sub-expressions that can be determined as never evaluated because they are in non-evaluated operands.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>int f(int a) {<br />
    volatile int i;<br />
    return ++a + sizeof(i); <br />
}</code></div></div> <br />
Accessing the volatile variable i is a persistent side effect, but since this access happens as part of a sizeof operand, that is not evaluated, no actual access to the volatile actually happens.<br />
<br />
Would it make sense to update this rule (and several other that use similar wording) to separate the undecidable case of infeasible paths from the very decidable case of non-evaluated expressions?<br />
<br />
FYI, in similar cases, MISRA C++ uses wording such as " even if they occur in an infeasible path" instead of "even if specified as not being evaluated".]]></description>
			<content:encoded><![CDATA[Hi there,<br />
<br />
Rule 13.3 says:<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>All sub-expressions of the <span style="font-style: italic;" class="mycode_i">full expression</span> are treated as if they were evaluated for the purposes of this rule, even if specified as not being evaluated by the C Standard.</blockquote>
<br />
I understand what it makes sense in the context for instance of the conditional operator, but I wanted to check it this applies the sub-expressions that can be determined as never evaluated because they are in non-evaluated operands.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>int f(int a) {<br />
    volatile int i;<br />
    return ++a + sizeof(i); <br />
}</code></div></div> <br />
Accessing the volatile variable i is a persistent side effect, but since this access happens as part of a sizeof operand, that is not evaluated, no actual access to the volatile actually happens.<br />
<br />
Would it make sense to update this rule (and several other that use similar wording) to separate the undecidable case of infeasible paths from the very decidable case of non-evaluated expressions?<br />
<br />
FYI, in similar cases, MISRA C++ uses wording such as " even if they occur in an infeasible path" instead of "even if specified as not being evaluated".]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[13.2 Was TC2 correctly applied to the rule in MISRA C:2023?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1771</link>
			<pubDate>Wed, 03 Jun 2026 15:27:35 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6753">Loïc</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1771</guid>
			<description><![CDATA[Hello,<br />
<br />
TC2 says:<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>TC 2.23 : In the “Amplification” section, number the existing two notes as 1 and 3 respectively. <br />
TC 2.24 : In the “Amplification” section, insert a new note 2 between the existing two notes: 2. All parts of the expression are considered when determining whether an object is read or modified, irrespective of any known values </blockquote>
<br />
But when looking at MISRA C:2023, we only see 2 notes, and the text that was supposed to be inserted as node 2 appears in second position in the bullet list above the notes.<br />
<br />
Which is right? The TC2, or the 2023 version?<br />
<br />
Thank you,]]></description>
			<content:encoded><![CDATA[Hello,<br />
<br />
TC2 says:<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>TC 2.23 : In the “Amplification” section, number the existing two notes as 1 and 3 respectively. <br />
TC 2.24 : In the “Amplification” section, insert a new note 2 between the existing two notes: 2. All parts of the expression are considered when determining whether an object is read or modified, irrespective of any known values </blockquote>
<br />
But when looking at MISRA C:2023, we only see 2 notes, and the text that was supposed to be inserted as node 2 appears in second position in the bullet list above the notes.<br />
<br />
Which is right? The TC2, or the 2023 version?<br />
<br />
Thank you,]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 13.3 incr/decr op in initialization]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1749</link>
			<pubDate>Thu, 04 Sep 2025 10:55:05 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6679">delirium5223</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1749</guid>
			<description><![CDATA[Based on the example in MISRA 2023 C this is non-compliant:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>  int u8a=0;  // implied<br />
  u8a = u8b++;  //don't accept assignment and increment on the same line</code></div></div><br />
  but what about in initialization? According to PCLP tool it's acceptable:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>  int u8a = u8b++;</code></div></div><br />
My view is that de/increment shouldn't be mixed with anything and it should be alone in one line to avoid any chance of confusion.<br />
<br />
Please clarify.]]></description>
			<content:encoded><![CDATA[Based on the example in MISRA 2023 C this is non-compliant:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>  int u8a=0;  // implied<br />
  u8a = u8b++;  //don't accept assignment and increment on the same line</code></div></div><br />
  but what about in initialization? According to PCLP tool it's acceptable:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>  int u8a = u8b++;</code></div></div><br />
My view is that de/increment shouldn't be mixed with anything and it should be alone in one line to avoid any chance of confusion.<br />
<br />
Please clarify.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 13.3 - Using ++/-- with a volatile variable in C]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1671</link>
			<pubDate>Tue, 06 Feb 2024 21:50:45 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6342">bsmith23</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1671</guid>
			<description><![CDATA[Hello, <br />
I saw in a previous post (<a href="https://forum.misra.org.uk/showthread.php?tid=1302" target="_blank" rel="noopener" class="mycode_url">https://forum.misra.org.uk/showthread.php?tid=1302</a>), it was discussed that <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>volatile int x = 0;<br />
x++;</code></div></div>where x is declared as volatile is a violation of rule 13.3 and changing this to be <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>x += 1;</code></div></div>results in compliance with rule 13.3. Would someone be able to explain why this is the case?]]></description>
			<content:encoded><![CDATA[Hello, <br />
I saw in a previous post (<a href="https://forum.misra.org.uk/showthread.php?tid=1302" target="_blank" rel="noopener" class="mycode_url">https://forum.misra.org.uk/showthread.php?tid=1302</a>), it was discussed that <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>volatile int x = 0;<br />
x++;</code></div></div>where x is declared as volatile is a violation of rule 13.3 and changing this to be <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>x += 1;</code></div></div>results in compliance with rule 13.3. Would someone be able to explain why this is the case?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 13.5]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1667</link>
			<pubDate>Fri, 17 Nov 2023 13:48:01 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6306">TomDK</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1667</guid>
			<description><![CDATA[<span style="font-size: small;" class="mycode_size">In our first project with MISRA we have a question.</span><br />
<span style="font-size: small;" class="mycode_size"> </span><br />
<span style="font-size: small;" class="mycode_size">The couple of “issues” with MISRA 2012 rule 13.5:</span><br />
<span style="font-size: small;" class="mycode_size"> </span><br />
<span style="font-size: small;" class="mycode_size">Variables:</span><br />
<span style="font-style: italic;" class="mycode_i"><span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">volatile uint8_t bMakeAlarm; (from interrupt)</span></span></span><br />
<span style="font-style: italic;" class="mycode_i"><span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">uint8_t bRelay;</span></span></span><br />
<span style="font-style: italic;" class="mycode_i"><span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">uint8_t bCountSW2High;</span></span></span><br />
<span style="font-style: italic;" class="mycode_i"><span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">uint8_t bPlayerPlaying;</span></span></span><br />
<span style="font-style: italic;" class="mycode_i"><span style="font-size: small;" class="mycode_size"> </span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"><span style="font-style: italic;" class="mycode_i">Info: SW2 = (PORTA.IN &amp; (uint8_t)PIN5_bm) is a “register” (CPU)</span></span></span><br />
<span style="font-size: small;" class="mycode_size"> </span><br />
<span style="font-size: small;" class="mycode_size">Original if statement</span><br />
<span style="font-size: small;" class="mycode_size"> </span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">if (SW2 == 0U || bMakeAlarm != 0U || bRelay != 0U || bCountSW2High != 0U || bPlayerPlaying != 0U)</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">{</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">  do_something;</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">}</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size">This makes the message 13.5 because bMakeAlarm is volatile.</span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size">If I change it a little bit to (removing the volatile):</span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">if (SW2 == 0U || bRelay != 0U || bCountSW2High != 0U || bPlayerPlaying != 0U)</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">{</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">  b100mSCount = 0U;</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">}</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size">This complies with MISRA. However if change it to this which is normally basically the same:</span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">if (bRelay != 0U || SW2 == 0U || bCountSW2High != 0U || bPlayerPlaying != 0U)</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">{</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">  b100mSCount = 0U;</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">}</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size">This not comply with 13.5, why?</span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size">Like in recommendations for the rule 13.5 this will work:</span><br />
<span style="font-size: small;" class="mycode_size"> </span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">SW2hold = SW2;</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">bMakeAlarmHold = bMakeAlarm;</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">    </span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">if (bRelay != 0U || SW2hold == 0U || bMakeAlarmHold != 0U || bCountSW2High != 0U || bPlayerPlaying != 0U)</span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">{</span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">  b100mSCount = 0U;</span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">}</span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size">What is the best solution?</span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Tahoma, sans-serif;" class="mycode_font">But not super readable and could lead to faults if you do not remember that the xxxHold is just a temp. Any other good work-a-rounds?</span></span><br />
<br />
<span style="font-size: small;" class="mycode_size">Thanks  <img src="https://forum.misra.org.uk/images/smilies/smile.png" alt="Smile" title="Smile" class="smilie smilie_1" /> <br />
<br />
</span>]]></description>
			<content:encoded><![CDATA[<span style="font-size: small;" class="mycode_size">In our first project with MISRA we have a question.</span><br />
<span style="font-size: small;" class="mycode_size"> </span><br />
<span style="font-size: small;" class="mycode_size">The couple of “issues” with MISRA 2012 rule 13.5:</span><br />
<span style="font-size: small;" class="mycode_size"> </span><br />
<span style="font-size: small;" class="mycode_size">Variables:</span><br />
<span style="font-style: italic;" class="mycode_i"><span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">volatile uint8_t bMakeAlarm; (from interrupt)</span></span></span><br />
<span style="font-style: italic;" class="mycode_i"><span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">uint8_t bRelay;</span></span></span><br />
<span style="font-style: italic;" class="mycode_i"><span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">uint8_t bCountSW2High;</span></span></span><br />
<span style="font-style: italic;" class="mycode_i"><span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">uint8_t bPlayerPlaying;</span></span></span><br />
<span style="font-style: italic;" class="mycode_i"><span style="font-size: small;" class="mycode_size"> </span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"><span style="font-style: italic;" class="mycode_i">Info: SW2 = (PORTA.IN &amp; (uint8_t)PIN5_bm) is a “register” (CPU)</span></span></span><br />
<span style="font-size: small;" class="mycode_size"> </span><br />
<span style="font-size: small;" class="mycode_size">Original if statement</span><br />
<span style="font-size: small;" class="mycode_size"> </span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">if (SW2 == 0U || bMakeAlarm != 0U || bRelay != 0U || bCountSW2High != 0U || bPlayerPlaying != 0U)</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">{</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">  do_something;</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">}</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size">This makes the message 13.5 because bMakeAlarm is volatile.</span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size">If I change it a little bit to (removing the volatile):</span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">if (SW2 == 0U || bRelay != 0U || bCountSW2High != 0U || bPlayerPlaying != 0U)</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">{</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">  b100mSCount = 0U;</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">}</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size">This complies with MISRA. However if change it to this which is normally basically the same:</span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">if (bRelay != 0U || SW2 == 0U || bCountSW2High != 0U || bPlayerPlaying != 0U)</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">{</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">  b100mSCount = 0U;</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">}</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size">This not comply with 13.5, why?</span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size">Like in recommendations for the rule 13.5 this will work:</span><br />
<span style="font-size: small;" class="mycode_size"> </span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">SW2hold = SW2;</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-style: italic;" class="mycode_i"><span style="font-family: Courier New;" class="mycode_font">bMakeAlarmHold = bMakeAlarm;</span></span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">    </span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">if (bRelay != 0U || SW2hold == 0U || bMakeAlarmHold != 0U || bCountSW2High != 0U || bPlayerPlaying != 0U)</span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">{</span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">  b100mSCount = 0U;</span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font">}</span></span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Courier New;" class="mycode_font"> </span></span><br />
<span style="font-size: small;" class="mycode_size">What is the best solution?</span><br />
<span style="font-size: small;" class="mycode_size"><span style="font-family: Tahoma, sans-serif;" class="mycode_font">But not super readable and could lead to faults if you do not remember that the xxxHold is just a temp. Any other good work-a-rounds?</span></span><br />
<br />
<span style="font-size: small;" class="mycode_size">Thanks  <img src="https://forum.misra.org.uk/images/smilies/smile.png" alt="Smile" title="Smile" class="smilie smilie_1" /> <br />
<br />
</span>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Side effects in floating point comparisons]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1597</link>
			<pubDate>Thu, 13 Jan 2022 21:27:28 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=1246">gdavis</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1597</guid>
			<description><![CDATA[Hello,<br />
<br />
A user is surprised that his compiler diagnoses the following as being a violation of MISRA 2012 13.5:<br />
<br />
<span style="font-family: Courier New;" class="mycode_font">int in_range(double a)</span><br />
<span style="font-family: Courier New;" class="mycode_font">{</span><br />
<span style="font-family: Courier New;" class="mycode_font">    int result = 0;</span><br />
<span style="font-family: Courier New;" class="mycode_font">    if (a &gt;= 10.0 &amp;&amp; a &lt;= 20.0) {</span><br />
<span style="font-family: Courier New;" class="mycode_font">        result = 1;</span><br />
<span style="font-family: Courier New;" class="mycode_font">    }</span><br />
<span style="font-family: Courier New;" class="mycode_font">    return result;</span><br />
<span style="font-family: Courier New;" class="mycode_font">}</span><br />
<br />
The reasoning behind the diagnostic is that with C99, floating point status bits (if implemented) are considered part of the program state, so floating point operations have implicit side effects.  See the footnote in C99 5.1.2.3.<br />
<br />
<br />
This kind of goes back to Directive 1.1 and various decisions about floating point.<br />
<br />
Does everyone agree that this should be considered a violation?  I would appreciate any other thoughts you may have.<br />
<br />
Thanks,<br />
<br />
-Greg]]></description>
			<content:encoded><![CDATA[Hello,<br />
<br />
A user is surprised that his compiler diagnoses the following as being a violation of MISRA 2012 13.5:<br />
<br />
<span style="font-family: Courier New;" class="mycode_font">int in_range(double a)</span><br />
<span style="font-family: Courier New;" class="mycode_font">{</span><br />
<span style="font-family: Courier New;" class="mycode_font">    int result = 0;</span><br />
<span style="font-family: Courier New;" class="mycode_font">    if (a &gt;= 10.0 &amp;&amp; a &lt;= 20.0) {</span><br />
<span style="font-family: Courier New;" class="mycode_font">        result = 1;</span><br />
<span style="font-family: Courier New;" class="mycode_font">    }</span><br />
<span style="font-family: Courier New;" class="mycode_font">    return result;</span><br />
<span style="font-family: Courier New;" class="mycode_font">}</span><br />
<br />
The reasoning behind the diagnostic is that with C99, floating point status bits (if implemented) are considered part of the program state, so floating point operations have implicit side effects.  See the footnote in C99 5.1.2.3.<br />
<br />
<br />
This kind of goes back to Directive 1.1 and various decisions about floating point.<br />
<br />
Does everyone agree that this should be considered a violation?  I would appreciate any other thoughts you may have.<br />
<br />
Thanks,<br />
<br />
-Greg]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 13.4 For statement operand assignment]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1595</link>
			<pubDate>Fri, 07 Jan 2022 10:46:12 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5799">shaw</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1595</guid>
			<description><![CDATA[The third operand of the for statement has an assignment. Does the calculation violate the result that the assignment operator should not be used?<br />
<br />
for ( pos = (&amp;dev-&gt;list)-&gt;next, q = pos-&gt;next; pos != (&amp;dev-&gt;list); pos = q, q = pos-&gt;next ) {/*        */}]]></description>
			<content:encoded><![CDATA[The third operand of the for statement has an assignment. Does the calculation violate the result that the assignment operator should not be used?<br />
<br />
for ( pos = (&amp;dev-&gt;list)-&gt;next, q = pos-&gt;next; pos != (&amp;dev-&gt;list); pos = q, q = pos-&gt;next ) {/*        */}]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[13.1 when initializing with address of volatile variable]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1448</link>
			<pubDate>Wed, 08 Aug 2018 03:51:01 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=2549">michael.metivier</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1448</guid>
			<description><![CDATA[13.1 indicates that an initializer list shall not contain persistent side effects, and gives an example of initializing with a volatile variable access.  I believe there would be general agreement that<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>volatile uint16_t v1;<br />
<br />
volatile uint16_t *a[1] = {&amp;v1};</code></div></div>does not count as an "access" and is therefore compliant.<br />
<br />
What about address of submembers of a volatile aggregate?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>struct foo<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;uint16_t bar;<br />
};<br />
volatile struct foo baz;<br />
volatile uint16_t *a[1] = {&amp;baz.bar};</code></div></div><br />
Our cross-compiler defines our microconroller's memory mapped registers by address, like so:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>struct foo<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;uint16_t bar;<br />
};<br />
#define REG1 (*(volatile uint16_t *)0x100)<br />
#define REG2 (*(volatile struct foo *)0x1000)<br />
<br />
volatile uint16_t *a[2] = {&amp;REG1, &amp;REG2.bar};</code></div></div>Are either of the members of this initializer list complaint?]]></description>
			<content:encoded><![CDATA[13.1 indicates that an initializer list shall not contain persistent side effects, and gives an example of initializing with a volatile variable access.  I believe there would be general agreement that<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>volatile uint16_t v1;<br />
<br />
volatile uint16_t *a[1] = {&amp;v1};</code></div></div>does not count as an "access" and is therefore compliant.<br />
<br />
What about address of submembers of a volatile aggregate?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>struct foo<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;uint16_t bar;<br />
};<br />
volatile struct foo baz;<br />
volatile uint16_t *a[1] = {&amp;baz.bar};</code></div></div><br />
Our cross-compiler defines our microconroller's memory mapped registers by address, like so:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>struct foo<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;uint16_t bar;<br />
};<br />
#define REG1 (*(volatile uint16_t *)0x100)<br />
#define REG2 (*(volatile struct foo *)0x1000)<br />
<br />
volatile uint16_t *a[2] = {&amp;REG1, &amp;REG2.bar};</code></div></div>Are either of the members of this initializer list complaint?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Is there any MISRA rule to find this sideeffect??]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1446</link>
			<pubDate>Fri, 03 Aug 2018 12:02:18 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5105">sprabhakars</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1446</guid>
			<description><![CDATA[I am not sure, if this potential problem is categorized under any MISRA rules??<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#include<br />
static unsigned short var2;<br />
int main()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned char var1 = 0;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (var1 &lt;&nbsp;&nbsp;var2)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var1++;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (void)printf("program completed &#92;n ");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<br />
}</code></div></div><br />
The variable var2 can have some value updated outside this function(may be more than 256) and causing a system crash as the while condition never fails.<br />
<br />
I run this with <span style="font-style: italic;" class="mycode_i">PC-Lint and Parasoft's </span>MISRA checker, both doesn't find any error with this portion of code.]]></description>
			<content:encoded><![CDATA[I am not sure, if this potential problem is categorized under any MISRA rules??<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#include<br />
static unsigned short var2;<br />
int main()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned char var1 = 0;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (var1 &lt;&nbsp;&nbsp;var2)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var1++;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (void)printf("program completed &#92;n ");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<br />
}</code></div></div><br />
The variable var2 can have some value updated outside this function(may be more than 256) and causing a system crash as the while condition never fails.<br />
<br />
I run this with <span style="font-style: italic;" class="mycode_i">PC-Lint and Parasoft's </span>MISRA checker, both doesn't find any error with this portion of code.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 13.2 Compliance]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1407</link>
			<pubDate>Wed, 21 Mar 2018 18:51:07 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4374">rcseacord</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1407</guid>
			<description><![CDATA[Does the following expression comply with Rule 13.2?<br />
<br />
(x = a) &amp;&amp; (x = b)<br />
<br />
What if it is preceded by the following declaration?<br />
<br />
int a = 0;<br />
<br />
Thanks,<br />
rCs]]></description>
			<content:encoded><![CDATA[Does the following expression comply with Rule 13.2?<br />
<br />
(x = a) &amp;&amp; (x = b)<br />
<br />
What if it is preceded by the following declaration?<br />
<br />
int a = 0;<br />
<br />
Thanks,<br />
rCs]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[rule 13.2: are const volatile variables volatile or not?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1368</link>
			<pubDate>Fri, 22 Sep 2017 14:05:05 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=837">ggoulas</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1368</guid>
			<description><![CDATA[Hi,<br />
<br />
Quick question about rule 13.2:<br />
the following variable:<br />
<br />
const volatile uint8_t myvar = 0;<br />
<br />
should it be considered as volatile or non-volatile in the context of rule 13.2 ?<br />
<br />
thank you.]]></description>
			<content:encoded><![CDATA[Hi,<br />
<br />
Quick question about rule 13.2:<br />
the following variable:<br />
<br />
const volatile uint8_t myvar = 0;<br />
<br />
should it be considered as volatile or non-volatile in the context of rule 13.2 ?<br />
<br />
thank you.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 13.6 - VLA, 'volatile' and Rule Exception]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1319</link>
			<pubDate>Tue, 28 Feb 2017 12:54:18 +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=1319</guid>
			<description><![CDATA[A qualifier in the declaration of an array applies to the element type, C11 6.7.3/9:<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>If the specification of an array type includes any type qualifiers, the element type is so-<br />
qualified, not the array type.</blockquote>
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>uint32_t f1 (int32_t x) {<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;volatile int32_t a1[x];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int32_t a2[x];<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return sizeof (a1) + sizeof (a2);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</code></div></div><br />
The Exception to this rule includes:<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>... is an lvalue with a volatile qualified type that is not a variable-length array...</blockquote>
<br />
Given that the qualifier applies to the element type and not the array type, "not a variable-length array" is always true for an lvalue with volatile type.  Is it the intention for 'sizeof(a1)' to be non compliant and for 'sizeof(a2)' to be  compliant?<br />
<br />
The Exception could be seen to add to the set of non-compliant cases even though nothing is written explicitly in the Amplification or Rationale.<br />
<br />
Regards,<br />
<br />
Richard]]></description>
			<content:encoded><![CDATA[A qualifier in the declaration of an array applies to the element type, C11 6.7.3/9:<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>If the specification of an array type includes any type qualifiers, the element type is so-<br />
qualified, not the array type.</blockquote>
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>uint32_t f1 (int32_t x) {<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;volatile int32_t a1[x];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int32_t a2[x];<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return sizeof (a1) + sizeof (a2);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</code></div></div><br />
The Exception to this rule includes:<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>... is an lvalue with a volatile qualified type that is not a variable-length array...</blockquote>
<br />
Given that the qualifier applies to the element type and not the array type, "not a variable-length array" is always true for an lvalue with volatile type.  Is it the intention for 'sizeof(a1)' to be non compliant and for 'sizeof(a2)' to be  compliant?<br />
<br />
The Exception could be seen to add to the set of non-compliant cases even though nothing is written explicitly in the Amplification or Rationale.<br />
<br />
Regards,<br />
<br />
Richard]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 13.3 incr/decr op with volatile]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1302</link>
			<pubDate>Tue, 03 Jan 2017 01:53:18 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=2439">minhyuk</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1302</guid>
			<description><![CDATA[Hello,<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>volatile int x;<br />
x++; // non-compliant - because, x declared with volatile</code></div></div><br />
In the above code, because 'x' variable is declared as volatile, I think it violates Rule 13.3. What do you think?]]></description>
			<content:encoded><![CDATA[Hello,<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>volatile int x;<br />
x++; // non-compliant - because, x declared with volatile</code></div></div><br />
In the above code, because 'x' variable is declared as volatile, I think it violates Rule 13.3. What do you think?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[R.13.5 When does a function have persistent side effects]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1171</link>
			<pubDate>Fri, 27 Mar 2015 13:28:57 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=196">misra-c</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1171</guid>
			<description><![CDATA[Consider the following example:<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>bool fn ( int x )<br />
 {<br />
&nbsp;&nbsp; static int y;<br />
&nbsp;&nbsp; if ( x &gt; 0 )<br />
&nbsp;&nbsp; {&nbsp;&nbsp; y = x;&nbsp;&nbsp;}&nbsp;&nbsp;/* causes persistent side effect if reached */<br />
&nbsp;&nbsp; return ....<br />
 }<br />
 <br />
 void call ( bool flag )<br />
 {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( flag &amp;&amp;&nbsp;&nbsp;fn(-3) ) /* Does RHS contain persistent side effect ? */<br />
&nbsp;&nbsp;&nbsp;&nbsp;{ .... }<br />
 }</code></div></div> In this example the call of "fn(-3)" never executes the code "y=x" and therefore no persistent side effect will occur.  <br />
 Is this a violation of rule 13.5?]]></description>
			<content:encoded><![CDATA[Consider the following example:<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>bool fn ( int x )<br />
 {<br />
&nbsp;&nbsp; static int y;<br />
&nbsp;&nbsp; if ( x &gt; 0 )<br />
&nbsp;&nbsp; {&nbsp;&nbsp; y = x;&nbsp;&nbsp;}&nbsp;&nbsp;/* causes persistent side effect if reached */<br />
&nbsp;&nbsp; return ....<br />
 }<br />
 <br />
 void call ( bool flag )<br />
 {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( flag &amp;&amp;&nbsp;&nbsp;fn(-3) ) /* Does RHS contain persistent side effect ? */<br />
&nbsp;&nbsp;&nbsp;&nbsp;{ .... }<br />
 }</code></div></div> In this example the call of "fn(-3)" never executes the code "y=x" and therefore no persistent side effect will occur.  <br />
 Is this a violation of rule 13.5?]]></content:encoded>
		</item>
	</channel>
</rss>