<?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.10 The essential type model]]></title>
		<link>https://forum.misra.org.uk/</link>
		<description><![CDATA[MISRA Discussion Forums - https://forum.misra.org.uk]]></description>
		<pubDate>Thu, 05 Nov 2026 13:31:09 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[10.3 Clarify if narrower in the title refers the the rank of the essential type]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1773</link>
			<pubDate>Thu, 25 Jun 2026 21:03:44 +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=1773</guid>
			<description><![CDATA[The rule 10.3 says:<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>The value of an expression shall not be assigned to an object with a narrower //essential type// </blockquote>
<br />
What does it mean to be narrower? To have a lower rank, or to have a smaller size?<br />
<br />
For instance, on a platform where <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>sizeof(long) == sizeof(long long)</code></div></div><br />
Is the following code compliant with rule 10.3:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>long l = 0;<br />
long long ll = 0;<br />
l = ll; // Compliant or not?</code></div></div><br />
My feeling is that it <span style="font-style: italic;" class="mycode_i">is </span>compliant, because the word <span style="font-style: italic;" class="mycode_i">rank </span>is not used here, while it is explicitly used in other parts of the rule, but I'm not 100% confident.]]></description>
			<content:encoded><![CDATA[The rule 10.3 says:<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>The value of an expression shall not be assigned to an object with a narrower //essential type// </blockquote>
<br />
What does it mean to be narrower? To have a lower rank, or to have a smaller size?<br />
<br />
For instance, on a platform where <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>sizeof(long) == sizeof(long long)</code></div></div><br />
Is the following code compliant with rule 10.3:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>long l = 0;<br />
long long ll = 0;<br />
l = ll; // Compliant or not?</code></div></div><br />
My feeling is that it <span style="font-style: italic;" class="mycode_i">is </span>compliant, because the word <span style="font-style: italic;" class="mycode_i">rank </span>is not used here, while it is explicitly used in other parts of the rule, but I'm not 100% confident.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[What is the UTLR of -1?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1772</link>
			<pubDate>Tue, 09 Jun 2026 09:36:31 +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=1772</guid>
			<description><![CDATA[I'm attempting to determine the essential type of the following expression:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>(unsigned short)1 - (unsigned short)2</code></div></div><br />
This is a operation subject to arithmetic conversion (D.7.9), both operands are essentially unsigned, and the expression is an integer constant expression, so according to item 4.1, the essential type of the result is the UTLR of the result.<br />
<br />
However, the result is a <span style="font-weight: bold;" class="mycode_b">signed</span> integer with the value -1. The following program demonstrates this:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#include &lt;stdio.h&gt;<br />
<br />
<br />
#define TYPE(x) _Generic((x), &#92;<br />
    int: printf("int&#92;n"), &#92;<br />
    unsigned int: printf("unsigned int&#92;n"), &#92;<br />
    default: printf("other&#92;n") &#92;<br />
)<br />
<br />
int main() {<br />
    TYPE(1u - 2u);  <br />
    TYPE(1 - 2);  <br />
    TYPE((unsigned short)1 - (unsigned short)2);<br />
}</code></div></div><br />
<br />
<br />
So we have to compute the UTLR of a negative value, which is not defined.<br />
<br />
Is there an error in my reasoning, or is this a limitation in the essential type system?]]></description>
			<content:encoded><![CDATA[I'm attempting to determine the essential type of the following expression:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>(unsigned short)1 - (unsigned short)2</code></div></div><br />
This is a operation subject to arithmetic conversion (D.7.9), both operands are essentially unsigned, and the expression is an integer constant expression, so according to item 4.1, the essential type of the result is the UTLR of the result.<br />
<br />
However, the result is a <span style="font-weight: bold;" class="mycode_b">signed</span> integer with the value -1. The following program demonstrates this:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#include &lt;stdio.h&gt;<br />
<br />
<br />
#define TYPE(x) _Generic((x), &#92;<br />
    int: printf("int&#92;n"), &#92;<br />
    unsigned int: printf("unsigned int&#92;n"), &#92;<br />
    default: printf("other&#92;n") &#92;<br />
)<br />
<br />
int main() {<br />
    TYPE(1u - 2u);  <br />
    TYPE(1 - 2);  <br />
    TYPE((unsigned short)1 - (unsigned short)2);<br />
}</code></div></div><br />
<br />
<br />
So we have to compute the UTLR of a negative value, which is not defined.<br />
<br />
Is there an error in my reasoning, or is this a limitation in the essential type system?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Typo in Appendix C of MISRA C:2023]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1730</link>
			<pubDate>Mon, 17 Mar 2025 14:58:24 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5921">Yordan Naydenov</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1730</guid>
			<description><![CDATA[Appendix C (C.1.1, p. 270 (hard copy) / p. 271 (pdf)<span style="color: #c19e00;" class="mycode_color">*</span>) of MISRA C:2023 (3rd Edn, 2nd Rev., April 2023) reads:<br />
"... as the examples below show (<span style="font-family: Courier New;" class="mycode_font">si</span> and <span style="font-family: Courier New;" class="mycode_font">ui</span> are 32-bit signed and unsigned integers and <span style="font-family: Courier New;" class="mycode_font">u8</span> is an 8-bit <span style="font-style: italic;" class="mycode_i">unsigned char</span>):"<br />
<br />
However, there is a lack of correspondence between the above-introduced unsigned char object identifier of <span style="font-family: Courier New;" class="mycode_font">u8</span> and the naming of an operand of unsigned char type in the table that follows immediately (viz. <span style="font-family: Courier New;" class="mycode_font">uc</span>, columns <span style="font-style: italic;" class="mycode_i">Expression</span> and <span style="font-style: italic;" class="mycode_i">Notes</span>). On page 273(274) (C.2.4, a distinct sub-section of the Appendix) such an unsigned char object of similar name is indeed used (<span style="font-family: Courier New;" class="mycode_font">u8a</span>), in line with the exemplary non-specific object names used in code fragments throughout the Guidelines' body of text (the naming convention introduced on p. 14).<br />
<br />
For the sake of ease of visually perceiving the types involved in the expressions and following through the implicit conversions they undergo, it is a good decision that concise, plain names such as <span style="font-family: Courier New;" class="mycode_font">si</span>, <span style="font-family: Courier New;" class="mycode_font">ui</span>, and <span style="font-family: Courier New;" class="mycode_font">uc</span> are used, instead of operand identifiers cluttered with numeric characters (as would be in <span style="font-family: Courier New;" class="mycode_font">s32</span>(<span style="font-family: Courier New;" class="mycode_font">i32</span>), <span style="font-family: Courier New;" class="mycode_font">u32</span> and <span style="font-family: Courier New;" class="mycode_font">u8</span>).<br />
<br />
Apparently, this lack of correspondence between the operand names in the table and their prior introduction in the text is inherited from the previous versions of the Guidelines (MISRA C:2012 – 3rd Edn, March 2013; 3rd Edn, 1st Rev., February 2019). Never corrected by subsequent Technical Corrigenda or Amendments to those. It is now present in MISRA C:2025 as well.<br />
<br />
Please, consider appending the erratum, reported in this separate forum thread<span style="color: #c19e00;" class="mycode_color">†</span>, to the dedicated <a href="https://misra.org.uk/misra-c-errata/" target="_blank" rel="noopener" class="mycode_url">MISRA C Errata</a> list maintained on the MISRA website, to keep it up-to-date and indeed a readily available single source of reference for all misprints found in MISRA C:2023, 3rd Edn, 2nd Rev.<br />
<br />
_____<br />
<br />
(<span style="color: #c19e00;" class="mycode_color">*</span>) Note that the text starts to disagree with the page numbering of the two documents (the electronic one and the hard copy) beginning from p. 229 onwards! This does not make favour to coherently referencing parts of the Guidelines and may lead to confusion and misunderstanding.<br />
<br />
(<span style="color: #c19e00;" class="mycode_color">†</span>) This thread is considered the most relevant one as Appendix C is referenced mostly in there, and as there are no dedicated threads specifically aimed at the appendices, or some other general means for reporting typographical and other errors.]]></description>
			<content:encoded><![CDATA[Appendix C (C.1.1, p. 270 (hard copy) / p. 271 (pdf)<span style="color: #c19e00;" class="mycode_color">*</span>) of MISRA C:2023 (3rd Edn, 2nd Rev., April 2023) reads:<br />
"... as the examples below show (<span style="font-family: Courier New;" class="mycode_font">si</span> and <span style="font-family: Courier New;" class="mycode_font">ui</span> are 32-bit signed and unsigned integers and <span style="font-family: Courier New;" class="mycode_font">u8</span> is an 8-bit <span style="font-style: italic;" class="mycode_i">unsigned char</span>):"<br />
<br />
However, there is a lack of correspondence between the above-introduced unsigned char object identifier of <span style="font-family: Courier New;" class="mycode_font">u8</span> and the naming of an operand of unsigned char type in the table that follows immediately (viz. <span style="font-family: Courier New;" class="mycode_font">uc</span>, columns <span style="font-style: italic;" class="mycode_i">Expression</span> and <span style="font-style: italic;" class="mycode_i">Notes</span>). On page 273(274) (C.2.4, a distinct sub-section of the Appendix) such an unsigned char object of similar name is indeed used (<span style="font-family: Courier New;" class="mycode_font">u8a</span>), in line with the exemplary non-specific object names used in code fragments throughout the Guidelines' body of text (the naming convention introduced on p. 14).<br />
<br />
For the sake of ease of visually perceiving the types involved in the expressions and following through the implicit conversions they undergo, it is a good decision that concise, plain names such as <span style="font-family: Courier New;" class="mycode_font">si</span>, <span style="font-family: Courier New;" class="mycode_font">ui</span>, and <span style="font-family: Courier New;" class="mycode_font">uc</span> are used, instead of operand identifiers cluttered with numeric characters (as would be in <span style="font-family: Courier New;" class="mycode_font">s32</span>(<span style="font-family: Courier New;" class="mycode_font">i32</span>), <span style="font-family: Courier New;" class="mycode_font">u32</span> and <span style="font-family: Courier New;" class="mycode_font">u8</span>).<br />
<br />
Apparently, this lack of correspondence between the operand names in the table and their prior introduction in the text is inherited from the previous versions of the Guidelines (MISRA C:2012 – 3rd Edn, March 2013; 3rd Edn, 1st Rev., February 2019). Never corrected by subsequent Technical Corrigenda or Amendments to those. It is now present in MISRA C:2025 as well.<br />
<br />
Please, consider appending the erratum, reported in this separate forum thread<span style="color: #c19e00;" class="mycode_color">†</span>, to the dedicated <a href="https://misra.org.uk/misra-c-errata/" target="_blank" rel="noopener" class="mycode_url">MISRA C Errata</a> list maintained on the MISRA website, to keep it up-to-date and indeed a readily available single source of reference for all misprints found in MISRA C:2023, 3rd Edn, 2nd Rev.<br />
<br />
_____<br />
<br />
(<span style="color: #c19e00;" class="mycode_color">*</span>) Note that the text starts to disagree with the page numbering of the two documents (the electronic one and the hard copy) beginning from p. 229 onwards! This does not make favour to coherently referencing parts of the Guidelines and may lead to confusion and misunderstanding.<br />
<br />
(<span style="color: #c19e00;" class="mycode_color">†</span>) This thread is considered the most relevant one as Appendix C is referenced mostly in there, and as there are no dedicated threads specifically aimed at the appendices, or some other general means for reporting typographical and other errors.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Explain deviation requirement]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1689</link>
			<pubDate>Tue, 18 Jun 2024 11:26:00 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6418">Gabriel</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1689</guid>
			<description><![CDATA[<span style="font-size: x-large;" class="mycode_size"><span style="color: #555555;" class="mycode_color">Hello, could someone explain the following deviation </span><span style="color: #555555;" class="mycode_color">requirement: </span></span><br />
<br />
<span style="font-size: x-large;" class="mycode_size"><span style="color: #555555;" class="mycode_color">"This deviation permit shall only be applied if the compiler's implementation has been verified to be consistent with the code generator's configuration (implicit or explicit)."</span></span><br />
<br />
<span style="font-size: x-large;" class="mycode_size"><span style="color: #555555;" class="mycode_color">It is mentiond in rule 10.3, 10.4 and 10.8.</span></span><br />
<span style="font-size: x-large;" class="mycode_size"><span style="color: #555555;" class="mycode_color">How to prove that this can be fullfilled? Could you refer to autocode?</span></span><br />
<br />
<span style="color: #555555;" class="mycode_color"><span style="font-size: x-large;" class="mycode_size">Thanks!</span></span>]]></description>
			<content:encoded><![CDATA[<span style="font-size: x-large;" class="mycode_size"><span style="color: #555555;" class="mycode_color">Hello, could someone explain the following deviation </span><span style="color: #555555;" class="mycode_color">requirement: </span></span><br />
<br />
<span style="font-size: x-large;" class="mycode_size"><span style="color: #555555;" class="mycode_color">"This deviation permit shall only be applied if the compiler's implementation has been verified to be consistent with the code generator's configuration (implicit or explicit)."</span></span><br />
<br />
<span style="font-size: x-large;" class="mycode_size"><span style="color: #555555;" class="mycode_color">It is mentiond in rule 10.3, 10.4 and 10.8.</span></span><br />
<span style="font-size: x-large;" class="mycode_size"><span style="color: #555555;" class="mycode_color">How to prove that this can be fullfilled? Could you refer to autocode?</span></span><br />
<br />
<span style="color: #555555;" class="mycode_color"><span style="font-size: x-large;" class="mycode_size">Thanks!</span></span>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Further guidance on MISRA-C 2012 Rule 10.6]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1681</link>
			<pubDate>Tue, 09 Apr 2024 14:29:12 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6377">mshawa</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1681</guid>
			<description><![CDATA[MISRA-C 2012 D.3 states that UTLR/STLR rules are only applied to integer constant expressions for operators that explicitly specify this in D.7. D.7 further states that the essential type is the standard type unless otherwise listed and does not specify a non-standard essential type for sizeof. <br />
<hr class="mycode_hr" />
Given the following example: <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef unsigned int uint32_t;<br />
typedef unsigned short uint16_t;<br />
extern uint16_t u16;<br />
extern uint32_t u32;<br />
<br />
extern void foo( void );<br />
void foo( void ) {<br />
    uint32_t case1 = (sizeof(uint32_t) + sizeof(uint32_t)) + u16; /*Case 1*/<br />
    uint32_t case2 = u32 + u32 + u16; /*Case 2*/<br />
    uint32_t case3 = sizeof(uint32_t) + (sizeof(uint32_t) + u16);/*Case 3*/<br />
    uint32_t case4 = sizeof(uint32_t) + u16 + sizeof(uint32_t); /*Case 4*/<br />
}</code></div></div><br />
Which of the cases violates Rule 10.6 while providing the rationale?]]></description>
			<content:encoded><![CDATA[MISRA-C 2012 D.3 states that UTLR/STLR rules are only applied to integer constant expressions for operators that explicitly specify this in D.7. D.7 further states that the essential type is the standard type unless otherwise listed and does not specify a non-standard essential type for sizeof. <br />
<hr class="mycode_hr" />
Given the following example: <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef unsigned int uint32_t;<br />
typedef unsigned short uint16_t;<br />
extern uint16_t u16;<br />
extern uint32_t u32;<br />
<br />
extern void foo( void );<br />
void foo( void ) {<br />
    uint32_t case1 = (sizeof(uint32_t) + sizeof(uint32_t)) + u16; /*Case 1*/<br />
    uint32_t case2 = u32 + u32 + u16; /*Case 2*/<br />
    uint32_t case3 = sizeof(uint32_t) + (sizeof(uint32_t) + u16);/*Case 3*/<br />
    uint32_t case4 = sizeof(uint32_t) + u16 + sizeof(uint32_t); /*Case 4*/<br />
}</code></div></div><br />
Which of the cases violates Rule 10.6 while providing the rationale?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[MISRA C:2012 Rule 10.8 Question]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1665</link>
			<pubDate>Sat, 11 Nov 2023 15:29:00 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6296">elfdream</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1665</guid>
			<description><![CDATA[The rule 10.8 states that "The value of a composite expression shall not be cast to a different essential type category or a wider essential type".<br />
<br />
I understand that casting to a wider type will cause incompatibilities for different compilers where int have different width, but I don't understand why we cannot cast it to a different essential type category with the same or less width. <br />
<br />
In other words, the example<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>(uint32_t)(int32_t+int32_t)&nbsp;&nbsp;/* Non-compliant */</code></div></div><br />
is non-compliant, but the rationale behind this is feels unclear to me, as this code does not have inconsistency between compilers.<br />
<br />
A possible explanation is that:<br />
(1) despite the fact that writing like this will guarantee consistent behavior across compilers and architectures, <br />
(2) it easily misleads an inexperienced human programmer to interpret the computation inside the "()" to be carried out in uint32_t, which is of course not the case,<br />
so this is banned.<br />
<br />
I want to know whether this human readability is the rational behind the first clause of the rule. Thanks for looking into this matter in advance!]]></description>
			<content:encoded><![CDATA[The rule 10.8 states that "The value of a composite expression shall not be cast to a different essential type category or a wider essential type".<br />
<br />
I understand that casting to a wider type will cause incompatibilities for different compilers where int have different width, but I don't understand why we cannot cast it to a different essential type category with the same or less width. <br />
<br />
In other words, the example<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>(uint32_t)(int32_t+int32_t)&nbsp;&nbsp;/* Non-compliant */</code></div></div><br />
is non-compliant, but the rationale behind this is feels unclear to me, as this code does not have inconsistency between compilers.<br />
<br />
A possible explanation is that:<br />
(1) despite the fact that writing like this will guarantee consistent behavior across compilers and architectures, <br />
(2) it easily misleads an inexperienced human programmer to interpret the computation inside the "()" to be carried out in uint32_t, which is of course not the case,<br />
so this is banned.<br />
<br />
I want to know whether this human readability is the rational behind the first clause of the rule. Thanks for looking into this matter in advance!]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[MISRA C:2012 Rule 10.8 Clarification]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1655</link>
			<pubDate>Mon, 14 Aug 2023 13:58:22 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5615">uk000032</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1655</guid>
			<description><![CDATA[MISRA C:2012 Rule 10.8 states "The value of a composite expression shall not be cast to a different essential type category or a wider essential type".<br />
<br />
One example of a violation given is:<br />
<br />
<span style="font-family: Courier New;" class="mycode_font">( uint32_t ) ( u16a + u16b ) /* Non-compliant - cast to wider</span><br />
<span style="font-family: Courier New;" class="mycode_font">                              * essential type */</span><br />
<br />
But what about:<br />
<br />
<span style="font-family: Courier New;" class="mycode_font">( uint32_t ) u16a + ( uint32_t ) u16b  /* Compliant? */</span><br />
<br />
This kind of thing does get flagged by Polyspace 2022b as a violation of Rule 10.8, but am I correct in thinking that casting the variables before the compound operator is applied means that this not in fact a violation?]]></description>
			<content:encoded><![CDATA[MISRA C:2012 Rule 10.8 states "The value of a composite expression shall not be cast to a different essential type category or a wider essential type".<br />
<br />
One example of a violation given is:<br />
<br />
<span style="font-family: Courier New;" class="mycode_font">( uint32_t ) ( u16a + u16b ) /* Non-compliant - cast to wider</span><br />
<span style="font-family: Courier New;" class="mycode_font">                              * essential type */</span><br />
<br />
But what about:<br />
<br />
<span style="font-family: Courier New;" class="mycode_font">( uint32_t ) u16a + ( uint32_t ) u16b  /* Compliant? */</span><br />
<br />
This kind of thing does get flagged by Polyspace 2022b as a violation of Rule 10.8, but am I correct in thinking that casting the variables before the compound operator is applied means that this not in fact a violation?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 10.4 and essentially signed integer constant expressions]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1559</link>
			<pubDate>Tue, 19 Jan 2021 14:34:47 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5577">jaska</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1559</guid>
			<description><![CDATA[Rule 10.3 exception 1 allows assigning a signed integer constant expression to an essentially unsigned type, if the value can be represented in that type; u8 = 2 * 24; is allowed.<br />
Rule 10.4 has no such exception<br />
Expressions like u32 &gt; 0, u8 != 0, and u32 += 1 violate rule 10.4.<br />
<br />
Now:<br />
<br />
uint32_t u32idem(uint32_t x) { return x; }<br />
bool less_u32(uint32_t a, uint32_b ) { return a &lt; b; }<br />
<br />
if (u32 &lt; u32idem(1)) { /* accepted by 10.3 and 10.4 */<br />
} else if (less_u32(u32, 3)) { /* accepted by 10.3 (and 10.4) */<br />
} else if (u32 &lt; 4u) { /* fine by 10.4 */<br />
} else if (u32 &lt; 7) { /* violates 10.4 */<br />
} else if (11u &gt; u32) { /* ok, remove u and it's not */<br />
} else {<br />
    switch (u32) {<br />
        case 23: /* ok */<br />
...<br />
<br />
Why are binary operators handled differently from assignments and switch cases?  I think the exception should be the same for both 10.3 and 10.4 ? <br />
<br />
Why is there no exception for Rule 10.4 allowing an integer constant expression to be used in a binary expression?]]></description>
			<content:encoded><![CDATA[Rule 10.3 exception 1 allows assigning a signed integer constant expression to an essentially unsigned type, if the value can be represented in that type; u8 = 2 * 24; is allowed.<br />
Rule 10.4 has no such exception<br />
Expressions like u32 &gt; 0, u8 != 0, and u32 += 1 violate rule 10.4.<br />
<br />
Now:<br />
<br />
uint32_t u32idem(uint32_t x) { return x; }<br />
bool less_u32(uint32_t a, uint32_b ) { return a &lt; b; }<br />
<br />
if (u32 &lt; u32idem(1)) { /* accepted by 10.3 and 10.4 */<br />
} else if (less_u32(u32, 3)) { /* accepted by 10.3 (and 10.4) */<br />
} else if (u32 &lt; 4u) { /* fine by 10.4 */<br />
} else if (u32 &lt; 7) { /* violates 10.4 */<br />
} else if (11u &gt; u32) { /* ok, remove u and it's not */<br />
} else {<br />
    switch (u32) {<br />
        case 23: /* ok */<br />
...<br />
<br />
Why are binary operators handled differently from assignments and switch cases?  I think the exception should be the same for both 10.3 and 10.4 ? <br />
<br />
Why is there no exception for Rule 10.4 allowing an integer constant expression to be used in a binary expression?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[10.4 violation for u8b + 2]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1558</link>
			<pubDate>Mon, 18 Jan 2021 13:27:41 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4216">fmteau</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1558</guid>
			<description><![CDATA[Hello MISRA Bulletin Board,<br />
<br />
I understand mixing signed and unsigned variables in arithmetic operations can really lead to unexpected results,<br />
but I really fail to see what is the risk in adding a constant value of 2 (SLTR of signed char) to an unsigned 8-bit (char) variable.<br />
<br />
Could you please elaborate what can possibly go wrong in this case?<br />
<br />
Thanks in advance.]]></description>
			<content:encoded><![CDATA[Hello MISRA Bulletin Board,<br />
<br />
I understand mixing signed and unsigned variables in arithmetic operations can really lead to unexpected results,<br />
but I really fail to see what is the risk in adding a constant value of 2 (SLTR of signed char) to an unsigned 8-bit (char) variable.<br />
<br />
Could you please elaborate what can possibly go wrong in this case?<br />
<br />
Thanks in advance.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[No operators in #if]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1557</link>
			<pubDate>Thu, 17 Dec 2020 08:29:23 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5562">John C</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1557</guid>
			<description><![CDATA[The MISRA checker I am using is rejecting operators in #if as noted in the following code.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define TRUE 1<br />
<br />
#define Condition1 TRUE<br />
#define Condition2 TRUE<br />
<br />
#if Condition1&nbsp;&nbsp; /* Accepted */<br />
#endif<br />
#if !Condition1&nbsp;&nbsp;/* Rejected */<br />
/* Rejection is because:<br />
Unpermitted operand to operator '!' [MISRA 2012 Rule 10.1, required]<br />
*/<br />
#endif<br />
#if Condition1 &amp;&amp; Condition2&nbsp;&nbsp;/* Rejected */<br />
/* Rejection is because:<br />
Unpermitted operand to operator '&amp;&amp;' [MISRA 2012 Rule 10.1, required]<br />
*/<br />
#endif<br />
#if Condition1 || Condition2&nbsp;&nbsp;/* Rejected */<br />
/* Rejection is because:<br />
Unpermitted operand to operator '||' [MISRA 2012 Rule 10.1, required]<br />
*/<br />
#endif</code></div></div>According to the supplier, the constant '1' (or '0' when used in the same way) is being interpreted as a signed int and therefore the operators '!', '&amp;&amp;' and '||' cannot be used with it.<br />
<br />
Is the checker's interpretation correct?]]></description>
			<content:encoded><![CDATA[The MISRA checker I am using is rejecting operators in #if as noted in the following code.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define TRUE 1<br />
<br />
#define Condition1 TRUE<br />
#define Condition2 TRUE<br />
<br />
#if Condition1&nbsp;&nbsp; /* Accepted */<br />
#endif<br />
#if !Condition1&nbsp;&nbsp;/* Rejected */<br />
/* Rejection is because:<br />
Unpermitted operand to operator '!' [MISRA 2012 Rule 10.1, required]<br />
*/<br />
#endif<br />
#if Condition1 &amp;&amp; Condition2&nbsp;&nbsp;/* Rejected */<br />
/* Rejection is because:<br />
Unpermitted operand to operator '&amp;&amp;' [MISRA 2012 Rule 10.1, required]<br />
*/<br />
#endif<br />
#if Condition1 || Condition2&nbsp;&nbsp;/* Rejected */<br />
/* Rejection is because:<br />
Unpermitted operand to operator '||' [MISRA 2012 Rule 10.1, required]<br />
*/<br />
#endif</code></div></div>According to the supplier, the constant '1' (or '0' when used in the same way) is being interpreted as a signed int and therefore the operators '!', '&amp;&amp;' and '||' cannot be used with it.<br />
<br />
Is the checker's interpretation correct?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Is it possible to define your own Boolean types?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1545</link>
			<pubDate>Mon, 06 Jul 2020 07:44:48 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5437">andrea96b1</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1545</guid>
			<description><![CDATA[Hello,<br />
<br />
I want to know if it is possible to define a Boolean type and do not use the one defined in the stdbool.h. Can I define Boolean like this: <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef uint8_t boolean;</code></div></div> and <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define TRUE 0x1</code></div></div> and <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define FALSE 0x0</code></div></div> ? And If I define Boolean in this way, what operations, which if done using standard booleans would I violate?<br />
<br />
Sorry in advance If the question is not too clear and If I made some mistake.]]></description>
			<content:encoded><![CDATA[Hello,<br />
<br />
I want to know if it is possible to define a Boolean type and do not use the one defined in the stdbool.h. Can I define Boolean like this: <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef uint8_t boolean;</code></div></div> and <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define TRUE 0x1</code></div></div> and <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define FALSE 0x0</code></div></div> ? And If I define Boolean in this way, what operations, which if done using standard booleans would I violate?<br />
<br />
Sorry in advance If the question is not too clear and If I made some mistake.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Essential type of ~(uint16_t)0x30]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1537</link>
			<pubDate>Thu, 09 Apr 2020 16:37:49 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=3331">grunwald</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1537</guid>
			<description><![CDATA[What is the essential type of "~(uint16_t)0x30" ?<br />
<br />
Going by Appendix D "Bitwise complement":<br />
 * The operand is essentially unsigned<br />
 * The operand is an integer constant expression<br />
 * The result of "~(uint16_t)0x30" is -49 of standard type int (assuming int is 32 bits and twos complement).<br />
 * The UTLR of -49 is ill-defined.<br />
<br />
Option 1: If the resulting constant is negative, convert it to the unsigned type corresponding to the expression's standard type, then use the UTLR of that converted value. This would result in "~(uint16_t)0x30" having essential type "unsigned int" (same as without the cast to uint16_t).<br />
<br />
Option 2: If the resulting constant is negative, treat the expression as if it was non-constant, using the essential type of the operand instead. This would result in "~(uint16_t)0x30" having essential type "uint16_t" (same as if 0x30 wasn't a compile-time constant).<br />
<br />
Option 3: If the resulting constant is negative, use the standard type for the essential type. This would result in "~(uint16_t)0x30" having essential type "signed int".<br />
<br />
This also affects other constant expressions producing negative values after integral promotion, e.g. "(uint16_t)300u - (uint16_t)301u".]]></description>
			<content:encoded><![CDATA[What is the essential type of "~(uint16_t)0x30" ?<br />
<br />
Going by Appendix D "Bitwise complement":<br />
 * The operand is essentially unsigned<br />
 * The operand is an integer constant expression<br />
 * The result of "~(uint16_t)0x30" is -49 of standard type int (assuming int is 32 bits and twos complement).<br />
 * The UTLR of -49 is ill-defined.<br />
<br />
Option 1: If the resulting constant is negative, convert it to the unsigned type corresponding to the expression's standard type, then use the UTLR of that converted value. This would result in "~(uint16_t)0x30" having essential type "unsigned int" (same as without the cast to uint16_t).<br />
<br />
Option 2: If the resulting constant is negative, treat the expression as if it was non-constant, using the essential type of the operand instead. This would result in "~(uint16_t)0x30" having essential type "uint16_t" (same as if 0x30 wasn't a compile-time constant).<br />
<br />
Option 3: If the resulting constant is negative, use the standard type for the essential type. This would result in "~(uint16_t)0x30" having essential type "signed int".<br />
<br />
This also affects other constant expressions producing negative values after integral promotion, e.g. "(uint16_t)300u - (uint16_t)301u".]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[10.3 "promoted type" of controlling expression]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1530</link>
			<pubDate>Thu, 27 Feb 2020 14:45:49 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=3331">grunwald</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1530</guid>
			<description><![CDATA[What exactly is meant by Rule 10.3 using "promoted type" in "The conversion of the constant expression in a switch statement’s case label to the promoted type of the controlling expression." ?<br />
Using the promoted type kinds of contradicts the rule title, which is using essential types.<br />
<br />
The following examples assume 10.3 uses the standard C type (after integer promotions) for the controlling expression.<br />
Does the promotion also apply to the case labels, or do we keep using the essential type there? Assuming we keep using the essential type for case labels, that leads to some surprising violations:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>uint8_t a = 1;<br />
switch (a) { // type promoted to "signed int"<br />
&nbsp;&nbsp;case 1u:&nbsp;&nbsp;// 10.3 violation because 1u is essentially unsigned, but the controlling expression is promoted to an essentially signed type?<br />
&nbsp;&nbsp;case -200: // compliant with 10.3, even though the case is impossible to reach due to the sign mismatch?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
}</code></div></div><br />
<br />
Is there a way to write the following switch that is compliant on both 16-bit and 32-bit machines?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>uint16_t num = ...;<br />
switch (num &gt;&gt; 1u) { // uint16_t promotes to 'signed int' or 'unsigned int' depending on "sizeof(uint16_t) == sizeof(int)"<br />
&nbsp;&nbsp;case 1u:&nbsp;&nbsp; // 10.3 violation where sizeof(int)&gt;2, because the controlling expression is promoted to an essentially signed type?<br />
&nbsp;&nbsp;case (uint16_t)2u:&nbsp;&nbsp;// 10.3 violation where sizeof(int)&gt;2, because the controlling expression is promoted to an essentially signed type?<br />
&nbsp;&nbsp;case 2:&nbsp;&nbsp;// I guess signed literals work in all cases, thanks to exception 3.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
}</code></div></div><br />
It would make more sense to use the essential type for both controlling expression and labels; or use the standard type for both.]]></description>
			<content:encoded><![CDATA[What exactly is meant by Rule 10.3 using "promoted type" in "The conversion of the constant expression in a switch statement’s case label to the promoted type of the controlling expression." ?<br />
Using the promoted type kinds of contradicts the rule title, which is using essential types.<br />
<br />
The following examples assume 10.3 uses the standard C type (after integer promotions) for the controlling expression.<br />
Does the promotion also apply to the case labels, or do we keep using the essential type there? Assuming we keep using the essential type for case labels, that leads to some surprising violations:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>uint8_t a = 1;<br />
switch (a) { // type promoted to "signed int"<br />
&nbsp;&nbsp;case 1u:&nbsp;&nbsp;// 10.3 violation because 1u is essentially unsigned, but the controlling expression is promoted to an essentially signed type?<br />
&nbsp;&nbsp;case -200: // compliant with 10.3, even though the case is impossible to reach due to the sign mismatch?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
}</code></div></div><br />
<br />
Is there a way to write the following switch that is compliant on both 16-bit and 32-bit machines?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>uint16_t num = ...;<br />
switch (num &gt;&gt; 1u) { // uint16_t promotes to 'signed int' or 'unsigned int' depending on "sizeof(uint16_t) == sizeof(int)"<br />
&nbsp;&nbsp;case 1u:&nbsp;&nbsp; // 10.3 violation where sizeof(int)&gt;2, because the controlling expression is promoted to an essentially signed type?<br />
&nbsp;&nbsp;case (uint16_t)2u:&nbsp;&nbsp;// 10.3 violation where sizeof(int)&gt;2, because the controlling expression is promoted to an essentially signed type?<br />
&nbsp;&nbsp;case 2:&nbsp;&nbsp;// I guess signed literals work in all cases, thanks to exception 3.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
}</code></div></div><br />
It would make more sense to use the essential type for both controlling expression and labels; or use the standard type for both.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 10.6 An expression shall not be assigned to a wider type]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1524</link>
			<pubDate>Mon, 27 Jan 2020 23:47:51 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5392">LordMordac</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1524</guid>
			<description><![CDATA[The full rule title is:<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>The value of a composite expression shall not be assigned to an object with a wider essential type</blockquote>
<br />
I am having a lively debate with my scanner vendor about the quality of their scans.  The following example code is generating the commented violation:<br />
[code]<br />
static inline uint32_t bit32 (uint32_t pos)<br />
{<br />
    static const uint32_t mask = 31U;<br />
    static const uint32_t one = 1U;<br />
<br />
    // Event misra_c_2012_rule_10_6_violation: Assigning composite expression "1U ]]></description>
			<content:encoded><![CDATA[The full rule title is:<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>The value of a composite expression shall not be assigned to an object with a wider essential type</blockquote>
<br />
I am having a lively debate with my scanner vendor about the quality of their scans.  The following example code is generating the commented violation:<br />
[code]<br />
static inline uint32_t bit32 (uint32_t pos)<br />
{<br />
    static const uint32_t mask = 31U;<br />
    static const uint32_t one = 1U;<br />
<br />
    // Event misra_c_2012_rule_10_6_violation: Assigning composite expression "1U ]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 10.3 - Bitfield narrower essential type]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1512</link>
			<pubDate>Thu, 24 Oct 2019 06:01:26 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5204">apereira</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1512</guid>
			<description><![CDATA[Hello,<br />
<br />
Assuming that I have the following structure and enum:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef struct s{<br />
&nbsp;&nbsp;unsigned int a:5;<br />
&nbsp;&nbsp;unsigned int b:1;<br />
&nbsp;&nbsp;unsigned int c:1;<br />
} s;<br />
<br />
typedef enum e{<br />
&nbsp;&nbsp;ZERO = 0,<br />
&nbsp;&nbsp;ONE = 1,<br />
&nbsp;&nbsp;TWO = 2,<br />
&nbsp;&nbsp;THREE = 3<br />
} e;</code></div></div><br />
Why does the following code trigger rule 10.3?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>s fcn(void)<br />
{<br />
&nbsp;&nbsp;s test;<br />
<br />
&nbsp;&nbsp;test.a = (unsigned int) THREE;<br />
<br />
&nbsp;&nbsp;return test;<br />
}</code></div></div>]]></description>
			<content:encoded><![CDATA[Hello,<br />
<br />
Assuming that I have the following structure and enum:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef struct s{<br />
&nbsp;&nbsp;unsigned int a:5;<br />
&nbsp;&nbsp;unsigned int b:1;<br />
&nbsp;&nbsp;unsigned int c:1;<br />
} s;<br />
<br />
typedef enum e{<br />
&nbsp;&nbsp;ZERO = 0,<br />
&nbsp;&nbsp;ONE = 1,<br />
&nbsp;&nbsp;TWO = 2,<br />
&nbsp;&nbsp;THREE = 3<br />
} e;</code></div></div><br />
Why does the following code trigger rule 10.3?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>s fcn(void)<br />
{<br />
&nbsp;&nbsp;s test;<br />
<br />
&nbsp;&nbsp;test.a = (unsigned int) THREE;<br />
<br />
&nbsp;&nbsp;return test;<br />
}</code></div></div>]]></content:encoded>
		</item>
	</channel>
</rss>