<?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 - 6.13 Control Statement Expressions]]></title>
		<link>https://forum.misra.org.uk/</link>
		<description><![CDATA[MISRA Discussion Forums - https://forum.misra.org.uk]]></description>
		<pubDate>Thu, 05 Nov 2026 19:06:20 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[1-bit bitfield in boolean expression]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=972</link>
			<pubDate>Mon, 22 Jul 2013 08:53:41 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=2796">holger_l</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=972</guid>
			<description><![CDATA[Hi,<br />
rule 13.2 makes an example how boolean data could be used in an expression:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>if ( y ) /* Not compliant, unless y is effectively Boolean data (e.g. a flag) */</code></div></div>The example refers to a Boolean-by-enforcement type referred to in the appendix. <br />
But what is with a 1-bit Bitfield? Is it a Boolean-by-construct?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>struct { unsigned int flag1: 1, flag2: 1;} var;<br />
...<br />
if (var.flag1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* violation of rule 13.2 ? */<br />
if (( var.flag1) &amp;&amp; (var.flag2)) /* violation of rule 12.6 ? */<br />
if ((!var.flag1) &amp;&amp; (var.flag2)) /* 2x violation of rule 12.6 ? */<br />
if ((var.flag1 == 0) &amp;&amp; (var.flag2 != 0)) /* OK, but clumsy and harder to read */</code></div></div>Thanks for a comment!]]></description>
			<content:encoded><![CDATA[Hi,<br />
rule 13.2 makes an example how boolean data could be used in an expression:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>if ( y ) /* Not compliant, unless y is effectively Boolean data (e.g. a flag) */</code></div></div>The example refers to a Boolean-by-enforcement type referred to in the appendix. <br />
But what is with a 1-bit Bitfield? Is it a Boolean-by-construct?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>struct { unsigned int flag1: 1, flag2: 1;} var;<br />
...<br />
if (var.flag1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* violation of rule 13.2 ? */<br />
if (( var.flag1) &amp;&amp; (var.flag2)) /* violation of rule 12.6 ? */<br />
if ((!var.flag1) &amp;&amp; (var.flag2)) /* 2x violation of rule 12.6 ? */<br />
if ((var.flag1 == 0) &amp;&amp; (var.flag2 != 0)) /* OK, but clumsy and harder to read */</code></div></div>Thanks for a comment!]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rules 13.4 Function call with float]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=965</link>
			<pubDate>Tue, 25 Jun 2013 14:34:49 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=2706">Bfr</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=965</guid>
			<description><![CDATA[Hello,<br />
<br />
As the rule 13.4 says : <span style="font-weight: bold;" class="mycode_b">The controlling expression of a for statement shall not contain any objects of floating type.</span><br />
<br />
But what about a function call with a float as parameter (example below) ?<br />
<br />
I am asking this in order to implement a MISRA rule checker.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>int32_t i = 0;<br />
float32_t float_var;<br />
<br />
[...]<br />
<br />
for (i = 0; i &lt; float_to_int(float_var); ++i)<br />
{<br />
[...]<br />
}</code></div></div><br />
It seems correct to me since the float is not really use in the controlling expression. But the rules says <span style="text-decoration: underline;" class="mycode_u">any objects</span> and that confuse me a little.<br />
<br />
Thanks,<br />
Ben]]></description>
			<content:encoded><![CDATA[Hello,<br />
<br />
As the rule 13.4 says : <span style="font-weight: bold;" class="mycode_b">The controlling expression of a for statement shall not contain any objects of floating type.</span><br />
<br />
But what about a function call with a float as parameter (example below) ?<br />
<br />
I am asking this in order to implement a MISRA rule checker.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>int32_t i = 0;<br />
float32_t float_var;<br />
<br />
[...]<br />
<br />
for (i = 0; i &lt; float_to_int(float_var); ++i)<br />
{<br />
[...]<br />
}</code></div></div><br />
It seems correct to me since the float is not really use in the controlling expression. But the rules says <span style="text-decoration: underline;" class="mycode_u">any objects</span> and that confuse me a little.<br />
<br />
Thanks,<br />
Ben]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[13.5 Loop control expression inconsistencies]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=902</link>
			<pubDate>Wed, 30 May 2012 10:19:09 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=1929">Dinesh</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=902</guid>
			<description><![CDATA[Dear Misra Committee,<br />
<br />
Going through the previous posts on the rule 13.5, I found an inconsistency between the answers given in:<br />
 1) <a href="http://www.misra.org.uk/forum/viewtopic.php?f=69&amp;t=272" target="_blank" rel="noopener" class="mycode_url">http://www.misra.org.uk/forum/viewtopic.php?f=69&amp;t=272</a><br />
 2) <a href="http://www.misra.org.uk/forum/viewtopic.php?f=69&amp;t=874" target="_blank" rel="noopener" class="mycode_url">http://www.misra.org.uk/forum/viewtopic.php?f=69&amp;t=874</a><br />
<br />
In the first post, the following was posted:<br />
<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>...<br />
Loop Control Variable is defined as any variable occurring in the first, second or third expressions. <br />
<br />
Loop Counter is defined as a Loop Control Variable which is,<br />
â€¢ Initialised in the first expression or Initialised prior to first expression;<br />
â€¢ In the second expression, the operand of a relational operator (= ); Note (1)<br />
â€¢ In the third expression, always incremented or decremented by a constant, or an expression which evaluates to the same value for the duration of the loop;<br />
â€¢ Not modified in the body of the loop.<br />
...<br />
Note 1: The equality operators (==, !=) should not be used because termination of the loop may not occur.<br />
...</blockquote>
<br />
In the second post, the following example was given and was confirmed to be compliant with MISRA C 13.5.<br />
<br />
[code]<br />
bool Test_Index(int32_t index, int32_t bound){<br />
   return (bool)(p]]></description>
			<content:encoded><![CDATA[Dear Misra Committee,<br />
<br />
Going through the previous posts on the rule 13.5, I found an inconsistency between the answers given in:<br />
 1) <a href="http://www.misra.org.uk/forum/viewtopic.php?f=69&amp;t=272" target="_blank" rel="noopener" class="mycode_url">http://www.misra.org.uk/forum/viewtopic.php?f=69&amp;t=272</a><br />
 2) <a href="http://www.misra.org.uk/forum/viewtopic.php?f=69&amp;t=874" target="_blank" rel="noopener" class="mycode_url">http://www.misra.org.uk/forum/viewtopic.php?f=69&amp;t=874</a><br />
<br />
In the first post, the following was posted:<br />
<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>...<br />
Loop Control Variable is defined as any variable occurring in the first, second or third expressions. <br />
<br />
Loop Counter is defined as a Loop Control Variable which is,<br />
â€¢ Initialised in the first expression or Initialised prior to first expression;<br />
â€¢ In the second expression, the operand of a relational operator (= ); Note (1)<br />
â€¢ In the third expression, always incremented or decremented by a constant, or an expression which evaluates to the same value for the duration of the loop;<br />
â€¢ Not modified in the body of the loop.<br />
...<br />
Note 1: The equality operators (==, !=) should not be used because termination of the loop may not occur.<br />
...</blockquote>
<br />
In the second post, the following example was given and was confirmed to be compliant with MISRA C 13.5.<br />
<br />
[code]<br />
bool Test_Index(int32_t index, int32_t bound){<br />
   return (bool)(p]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[13.5 for() loops - does simplicity matter?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=845</link>
			<pubDate>Tue, 13 Sep 2011 07:51:48 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=1743">JohnC</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=845</guid>
			<description><![CDATA[I have compiled the following code.  The compiler accepts the first loop (ending at X) but rejects the other two (ending at X+2 and at X*2)<br />
<br />
extern tUI16 X, Y;<br />
void Fn( void )<br />
{<br />
  tUI16 i;<br />
  for( i = 0u; i &lt; X; i++ ) /* accepted */<br />
  {<br />
    Y += i;<br />
  }<br />
  for( i = 0u; i &lt; (X + 2u); i++ ) /* rejected */<br />
  {<br />
    Y += i;<br />
  }<br />
  for( i = 0u; i &lt; (X * 2u); i++ ) /* rejected */<br />
  {<br />
    Y += i;<br />
  }<br />
}<br />
<br />
The compiler suppliers say the compiler will accept the second expression if it is "a simple test" and that X+2 and X*2 do not pass this test.  I feel this is being too restrictive for rule 13.5.  Please may I have an opinion on this.<br />
<br />
Thanks,<br />
<br />
John]]></description>
			<content:encoded><![CDATA[I have compiled the following code.  The compiler accepts the first loop (ending at X) but rejects the other two (ending at X+2 and at X*2)<br />
<br />
extern tUI16 X, Y;<br />
void Fn( void )<br />
{<br />
  tUI16 i;<br />
  for( i = 0u; i &lt; X; i++ ) /* accepted */<br />
  {<br />
    Y += i;<br />
  }<br />
  for( i = 0u; i &lt; (X + 2u); i++ ) /* rejected */<br />
  {<br />
    Y += i;<br />
  }<br />
  for( i = 0u; i &lt; (X * 2u); i++ ) /* rejected */<br />
  {<br />
    Y += i;<br />
  }<br />
}<br />
<br />
The compiler suppliers say the compiler will accept the second expression if it is "a simple test" and that X+2 and X*2 do not pass this test.  I feel this is being too restrictive for rule 13.5.  Please may I have an opinion on this.<br />
<br />
Thanks,<br />
<br />
John]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Why is the code below cited for violation of MISRA 13.6]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=812</link>
			<pubDate>Thu, 03 Mar 2011 09:33:52 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=1183">kalpak</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=812</guid>
			<description><![CDATA[Why is the last code line (array element initialization) in the code below being cited for 13.6 violation by Crystal Revs MISRA checker: <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/*Test code for Crystal revs MISRA rule 13.6 */<br />
typedef unsigned char uint8_t<br />
void InitArray(void);<br />
<br />
#define LCD_NUM_OF_COLS 2u<br />
#define LCD_NUM_OF_ROWS&nbsp;&nbsp;&nbsp;&nbsp;10u<br />
uint8_t Test_Array[LCD_NUM_OF_COLS][LCD_NUM_OF_ROWS];<br />
<br />
void InitArray(void)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;uint8_t row_index = 0u;<br />
&nbsp;&nbsp;&nbsp;&nbsp;uint8_t col_index = 0u;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;for (col_index = 0u; col_index &lt; LCD_NUM_OF_COLS; col_index++)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (row_index=0u; row_index &lt; LCD_NUM_OF_ROWS; row_index++)&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;&nbsp;&nbsp;/*&nbsp;&nbsp;&nbsp;&nbsp;make each element of the array the char NULL&nbsp;&nbsp;&nbsp;&nbsp;*/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Test_Array[col_index][row_index] = 0u;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</code></div></div><br />
thanks,<br />
kalpak]]></description>
			<content:encoded><![CDATA[Why is the last code line (array element initialization) in the code below being cited for 13.6 violation by Crystal Revs MISRA checker: <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/*Test code for Crystal revs MISRA rule 13.6 */<br />
typedef unsigned char uint8_t<br />
void InitArray(void);<br />
<br />
#define LCD_NUM_OF_COLS 2u<br />
#define LCD_NUM_OF_ROWS&nbsp;&nbsp;&nbsp;&nbsp;10u<br />
uint8_t Test_Array[LCD_NUM_OF_COLS][LCD_NUM_OF_ROWS];<br />
<br />
void InitArray(void)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;uint8_t row_index = 0u;<br />
&nbsp;&nbsp;&nbsp;&nbsp;uint8_t col_index = 0u;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;for (col_index = 0u; col_index &lt; LCD_NUM_OF_COLS; col_index++)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (row_index=0u; row_index &lt; LCD_NUM_OF_ROWS; row_index++)&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;&nbsp;&nbsp;/*&nbsp;&nbsp;&nbsp;&nbsp;make each element of the array the char NULL&nbsp;&nbsp;&nbsp;&nbsp;*/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Test_Array[col_index][row_index] = 0u;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</code></div></div><br />
thanks,<br />
kalpak]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 13.3 with respect to 0.0]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=750</link>
			<pubDate>Tue, 13 Jul 2010 16:58:40 +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=750</guid>
			<description><![CDATA[Does rule 13.3 permit testing a floating point expression against 0.0?<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f( float flt )<br />
{<br />
if( flt == 0.0 )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{}<br />
}</code></div></div><br />
If not, how is this test any different than<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f( float flt )<br />
{<br />
if( !flt )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{}<br />
}</code></div></div>?<br />
<br />
Or does 13.3 not permit the second example either?]]></description>
			<content:encoded><![CDATA[Does rule 13.3 permit testing a floating point expression against 0.0?<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f( float flt )<br />
{<br />
if( flt == 0.0 )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{}<br />
}</code></div></div><br />
If not, how is this test any different than<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f( float flt )<br />
{<br />
if( !flt )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{}<br />
}</code></div></div>?<br />
<br />
Or does 13.3 not permit the second example either?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Doubt on rule 13.2]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=628</link>
			<pubDate>Mon, 16 Feb 2009 13:01:24 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=606">roberto</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=628</guid>
			<description><![CDATA[One of the examples given for rule 13.2 is:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>if ( y ) /* Not compliant, unless y is effectively Boolean data<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(e.g. a flag) */</code></div></div><br />
Would it still be not compliant if y is of pointer type?<br />
In case it is compliant, should 13.2 be interpreted as to be applicable only to expressions of integral type?]]></description>
			<content:encoded><![CDATA[One of the examples given for rule 13.2 is:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>if ( y ) /* Not compliant, unless y is effectively Boolean data<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(e.g. a flag) */</code></div></div><br />
Would it still be not compliant if y is of pointer type?<br />
In case it is compliant, should 13.2 be interpreted as to be applicable only to expressions of integral type?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[13.5 clarification on loop index iusage]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=577</link>
			<pubDate>Thu, 04 Sep 2008 09:23:36 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=672">Alexandre Langenieux</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=577</guid>
			<description><![CDATA[Dear Misra Committee,<br />
<br />
Rule 13.5 seems not clearly explicit about the content of the <span style="font-style: italic;" class="mycode_i">for</span> expressions.<br />
<ul class="mycode_list"><li>First expression: Initialization of the loop coounter if present. Can we consider as valid code the following examples:<br />
[code]<br />
int32_t i=0;<br />
<br />
for (i++;i</li>
</ul>
]]></description>
			<content:encoded><![CDATA[Dear Misra Committee,<br />
<br />
Rule 13.5 seems not clearly explicit about the content of the <span style="font-style: italic;" class="mycode_i">for</span> expressions.<br />
<ul class="mycode_list"><li>First expression: Initialization of the loop coounter if present. Can we consider as valid code the following examples:<br />
[code]<br />
int32_t i=0;<br />
<br />
for (i++;i</li>
</ul>
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 13.4 clarification]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=576</link>
			<pubDate>Mon, 01 Sep 2008 15:38:05 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=672">Alexandre Langenieux</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=576</guid>
			<description><![CDATA[Dear Misra committee,<br />
<br />
The rule 13.4 says:<br />
<span style="font-weight: bold;" class="mycode_b">The controlling expression of a <span style="font-style: italic;" class="mycode_i">for</span> statement shall not contain any objects of floating type.</span><br />
<br />
Does it apply only to loop counter, as suggest in the text explaining the rule ( ... floating-point variables shall not be used for this purpose [loop counter] ...). or to all operand of a controlling expression ?<br />
<br />
I mean, can we consider the following <span style="font-style: italic;" class="mycode_i">for</span> loop as compliant ?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>extern float32_t foo(void);<br />
<br />
int32_t i;<br />
float32_t f;<br />
<br />
for (i=0; i 1.0 &amp;&amp; f &lt; 3.0) ; i++){<br />
&nbsp;&nbsp;...<br />
&nbsp;&nbsp;f = foo()<br />
&nbsp;&nbsp;...<br />
}</code></div></div><br />
Thanks, Alexandre.]]></description>
			<content:encoded><![CDATA[Dear Misra committee,<br />
<br />
The rule 13.4 says:<br />
<span style="font-weight: bold;" class="mycode_b">The controlling expression of a <span style="font-style: italic;" class="mycode_i">for</span> statement shall not contain any objects of floating type.</span><br />
<br />
Does it apply only to loop counter, as suggest in the text explaining the rule ( ... floating-point variables shall not be used for this purpose [loop counter] ...). or to all operand of a controlling expression ?<br />
<br />
I mean, can we consider the following <span style="font-style: italic;" class="mycode_i">for</span> loop as compliant ?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>extern float32_t foo(void);<br />
<br />
int32_t i;<br />
float32_t f;<br />
<br />
for (i=0; i 1.0 &amp;&amp; f &lt; 3.0) ; i++){<br />
&nbsp;&nbsp;...<br />
&nbsp;&nbsp;f = foo()<br />
&nbsp;&nbsp;...<br />
}</code></div></div><br />
Thanks, Alexandre.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Infinite loop]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=396</link>
			<pubDate>Wed, 12 Sep 2007 13:29:11 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=286">JonM</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=396</guid>
			<description><![CDATA[What is the preferred implementation of an infinite loop?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>for ( ; ; ) ...</code></div></div><br />
or<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>while (1 == 1) ...</code></div></div><br />
or<br />
<br />
something else?<br />
<br />
Thanks in advance.<br />
<br />
Jonathan]]></description>
			<content:encoded><![CDATA[What is the preferred implementation of an infinite loop?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>for ( ; ; ) ...</code></div></div><br />
or<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>while (1 == 1) ...</code></div></div><br />
or<br />
<br />
something else?<br />
<br />
Thanks in advance.<br />
<br />
Jonathan]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Does 13.7 apply to ALL invariant Boolean expressions?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=203</link>
			<pubDate>Tue, 31 Jan 2006 22:12:45 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=203">rmgalles</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=203</guid>
			<description><![CDATA[The example only shows relational operators { &lt;  &gt;= }.<br />
<br />
What about other operators?<br />
#define OPTION_ONE 0x01<br />
#define OPTION_TWO 0x02<br />
<br />
#define MY_OPTIONS (OPTION_ONE)<br />
- or -<br />
#define MY_OPTIONS (OPTION_TWO)<br />
- or -<br />
#define MY_OPTIONS (0x00)<br />
- or -<br />
#define MY_OPTIONS (OPTION_ONE | OPTION_TWO)<br />
<br />
<br />
if ((MY_OPTIONS &amp; OPTION_ONE) != 0)  /* deviation from 13.7? */<br />
{<br />
   ...<br />
}<br />
<br />
<br />
In this case, equality operators { == != } are less likely to \"accidentally\" be always true/false (vs. intentionally always true/false), while relational operators can sometimes catch the programmer of guard (due to limited ranges of smaller integer types: [-128 to +127], [0 to +255], etc.<br />
<br />
<br />
What about sub-expressions?<br />
if ((u8 ]]></description>
			<content:encoded><![CDATA[The example only shows relational operators { &lt;  &gt;= }.<br />
<br />
What about other operators?<br />
#define OPTION_ONE 0x01<br />
#define OPTION_TWO 0x02<br />
<br />
#define MY_OPTIONS (OPTION_ONE)<br />
- or -<br />
#define MY_OPTIONS (OPTION_TWO)<br />
- or -<br />
#define MY_OPTIONS (0x00)<br />
- or -<br />
#define MY_OPTIONS (OPTION_ONE | OPTION_TWO)<br />
<br />
<br />
if ((MY_OPTIONS &amp; OPTION_ONE) != 0)  /* deviation from 13.7? */<br />
{<br />
   ...<br />
}<br />
<br />
<br />
In this case, equality operators { == != } are less likely to \"accidentally\" be always true/false (vs. intentionally always true/false), while relational operators can sometimes catch the programmer of guard (due to limited ranges of smaller integer types: [-128 to +127], [0 to +255], etc.<br />
<br />
<br />
What about sub-expressions?<br />
if ((u8 ]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[What is the essential requirement of Rule 13.3 ?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=42</link>
			<pubDate>Fri, 09 Sep 2005 13:39:31 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=0">Gavin McCall</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=42</guid>
			<description><![CDATA[Question: What is the essential requirement of Rule 13.3 ?<br />
<br />
Rule 13.3 only prohibits the use of == and !=. <br />
<br />
Does this mean that it is legitimate to use the &gt;= and  10.0f )   /* compliant */<br />
â€¦<br />
if ( speed = (10.0f â€“ tolerance)) &amp;&amp; ( speed ]]></description>
			<content:encoded><![CDATA[Question: What is the essential requirement of Rule 13.3 ?<br />
<br />
Rule 13.3 only prohibits the use of == and !=. <br />
<br />
Does this mean that it is legitimate to use the &gt;= and  10.0f )   /* compliant */<br />
â€¦<br />
if ( speed = (10.0f â€“ tolerance)) &amp;&amp; ( speed ]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[13.5 for() loops]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=25</link>
			<pubDate>Fri, 25 Feb 2005 17:02:19 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=81">matth1j</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=25</guid>
			<description><![CDATA[Hi<br />
<br />
Rule 13.5 (required) states: \"The 3 expressions of a for statement shall be concerned only with loop control\", and<br />
\"First expression: initialising the loop counter.<br />
Second expression: shall include testing the loop counter, and optionally other loop control variables.<br />
Third expression: increment or decrement of the loop counter.\"<br />
<br />
The implication would appear to be that for() loops should only be used where there is a loop counter. Is that correct, or could you (for example) use a for() loop without a loop counter, in which case there wouldn't be a first expression?<br />
<br />
Is the idea to restrict C's for() usage to that of Pascal's ie.<br />
<br />
for var := first [ to | downto ] last do ...<br />
<br />
? I'm Ok with this, but I feel that either I'm missing something or the rule isn't explicit enough about what for() can and can't be used for.<br />
<br />
Regards<br />
John<br />
NEC Technologies (UK)]]></description>
			<content:encoded><![CDATA[Hi<br />
<br />
Rule 13.5 (required) states: \"The 3 expressions of a for statement shall be concerned only with loop control\", and<br />
\"First expression: initialising the loop counter.<br />
Second expression: shall include testing the loop counter, and optionally other loop control variables.<br />
Third expression: increment or decrement of the loop counter.\"<br />
<br />
The implication would appear to be that for() loops should only be used where there is a loop counter. Is that correct, or could you (for example) use a for() loop without a loop counter, in which case there wouldn't be a first expression?<br />
<br />
Is the idea to restrict C's for() usage to that of Pascal's ie.<br />
<br />
for var := first [ to | downto ] last do ...<br />
<br />
? I'm Ok with this, but I feel that either I'm missing something or the rule isn't explicit enough about what for() can and can't be used for.<br />
<br />
Regards<br />
John<br />
NEC Technologies (UK)]]></content:encoded>
		</item>
	</channel>
</rss>