<?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.12 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 15:13:44 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[is a cast compliant with Rule 12.4]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1707</link>
			<pubDate>Mon, 30 Sep 2024 08:25:47 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5801">sowisojh</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1707</guid>
			<description><![CDATA[Is the cast in the following code compliant with MISRA2023 Rule 12.4, assuming a machine having int as 32 bit?<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#include &lt;stdint.h&gt;<br />
<br />
#define USEFUL_BIT ((uint16_t)0x0020u)<br />
<br />
uint16_t clear_useful_bit(uint16_t bitmask)<br />
{<br />
  uint16_t cleared_mask = bitmask;<br />
<br />
  cleared_mask &amp;= (uint16_t)~USEFUL_BIT;<br />
<br />
  return cleared_mask;<br />
}</code></div></div><br />
According to Appendix D.7.5 1.1 the result of ~ is the UTRL of the result. Assuming an 32 bit integer machine this would be 4294967263u. The result of the cast to uint16_t would be perform a "repeatedly [...] subtracting one more than the maximum value that can be represented in the new type until the value is in the new type" which leads to 65503. <br />
<br />
Is this type conversion treated as "unsigned integer wrap-around" in the sense of Rule 12.4 ?]]></description>
			<content:encoded><![CDATA[Is the cast in the following code compliant with MISRA2023 Rule 12.4, assuming a machine having int as 32 bit?<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#include &lt;stdint.h&gt;<br />
<br />
#define USEFUL_BIT ((uint16_t)0x0020u)<br />
<br />
uint16_t clear_useful_bit(uint16_t bitmask)<br />
{<br />
  uint16_t cleared_mask = bitmask;<br />
<br />
  cleared_mask &amp;= (uint16_t)~USEFUL_BIT;<br />
<br />
  return cleared_mask;<br />
}</code></div></div><br />
According to Appendix D.7.5 1.1 the result of ~ is the UTRL of the result. Assuming an 32 bit integer machine this would be 4294967263u. The result of the cast to uint16_t would be perform a "repeatedly [...] subtracting one more than the maximum value that can be represented in the new type until the value is in the new type" which leads to 65503. <br />
<br />
Is this type conversion treated as "unsigned integer wrap-around" in the sense of Rule 12.4 ?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 12.5 - sized and unsized array parameters]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1256</link>
			<pubDate>Sat, 11 Jun 2016 00:23:02 +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=1256</guid>
			<description><![CDATA[Does Rule 12.5 from AMD-1 apply to unsized array parameters (those without a size between the brackets)?  E.g.:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f(int32_t A[4], int32_t B[]) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;uint32_t sizeA = sizeof(A);&nbsp;&nbsp;// Obvious violation of 12.5<br />
&nbsp;&nbsp;&nbsp;&nbsp;uint32_t sizeB = sizeof(B);&nbsp;&nbsp;// Violation of 12.5?<br />
}</code></div></div><br />
The snippets in the amplification, rationale, and examples exclusively use sized arrays and the rationale does not seem to apply as strongly to unsized array parameters but the rule does not specify that it only applies to sized arrays or to both sized and unsized arrays.  Can you please clarify the intention here?]]></description>
			<content:encoded><![CDATA[Does Rule 12.5 from AMD-1 apply to unsized array parameters (those without a size between the brackets)?  E.g.:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f(int32_t A[4], int32_t B[]) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;uint32_t sizeA = sizeof(A);&nbsp;&nbsp;// Obvious violation of 12.5<br />
&nbsp;&nbsp;&nbsp;&nbsp;uint32_t sizeB = sizeof(B);&nbsp;&nbsp;// Violation of 12.5?<br />
}</code></div></div><br />
The snippets in the amplification, rationale, and examples exclusively use sized arrays and the rationale does not seem to apply as strongly to unsized array parameters but the rule does not specify that it only applies to sized arrays or to both sized and unsized arrays.  Can you please clarify the intention here?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Definition of "constant expression"]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1010</link>
			<pubDate>Mon, 16 Dec 2013 17:15:39 +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=1010</guid>
			<description><![CDATA[For rule 12.4, what definition of "constant expression" is used? If the definition is the one from the ISO C standards, that definition does not make it clear the example <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>const uint16_t c = 0xffffu;<br />
uint16_t y = c + 1u;</code></div></div> is compliant because a constant variable, if initialized with a constant expression "can be evaluated during translation rather than runtime".<br />
<br />
For the record, different compilers appear to take different approaches as to whether or not a const-qualified variable meets the definition of a "constant expression".]]></description>
			<content:encoded><![CDATA[For rule 12.4, what definition of "constant expression" is used? If the definition is the one from the ISO C standards, that definition does not make it clear the example <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>const uint16_t c = 0xffffu;<br />
uint16_t y = c + 1u;</code></div></div> is compliant because a constant variable, if initialized with a constant expression "can be evaluated during translation rather than runtime".<br />
<br />
For the record, different compilers appear to take different approaches as to whether or not a const-qualified variable meets the definition of a "constant expression".]]></content:encoded>
		</item>
	</channel>
</rss>