<?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.11 Pointer type conversions]]></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:24:08 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[11.6 pointer to pointer to void]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1765</link>
			<pubDate>Tue, 17 Mar 2026 20:43:04 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6164">dunno</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1765</guid>
			<description><![CDATA[Hi, does this rule apply also for pointer to pointer to void?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void * ptr;<br />
<br />
uint32_t addr = (uint32_t)&amp;ptr;</code></div></div><br />
or does this code violate any of the other rules?]]></description>
			<content:encoded><![CDATA[Hi, does this rule apply also for pointer to pointer to void?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void * ptr;<br />
<br />
uint32_t addr = (uint32_t)&amp;ptr;</code></div></div><br />
or does this code violate any of the other rules?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[11.9 and function calls and returned pointers]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1738</link>
			<pubDate>Mon, 26 May 2025 07:22:04 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5809">danielmarjamaki2</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1738</guid>
			<description><![CDATA[Could you please clarify to me if this violates 11.9:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>int* f1(void) {<br />
    return 0;  // 11.9 ?<br />
}</code></div></div><br />
And does this violate 11.9:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f2(int* ptr);<br />
<br />
void f3(void) {<br />
    f2(0);<br />
}</code></div></div><br />
Do you consider returns and function calls to be "assignments" otherwise it seems to me that the Amplification says these are compliant?<br />
<br />
The last example in the PDF does suggest that function calls should be considered to be "assignments" however there is no non-compliant example code that I can rely on.<br />
<br />
Thank you]]></description>
			<content:encoded><![CDATA[Could you please clarify to me if this violates 11.9:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>int* f1(void) {<br />
    return 0;  // 11.9 ?<br />
}</code></div></div><br />
And does this violate 11.9:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f2(int* ptr);<br />
<br />
void f3(void) {<br />
    f2(0);<br />
}</code></div></div><br />
Do you consider returns and function calls to be "assignments" otherwise it seems to me that the Amplification says these are compliant?<br />
<br />
The last example in the PDF does suggest that function calls should be considered to be "assignments" however there is no non-compliant example code that I can rely on.<br />
<br />
Thank you]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Strict aliasing rule]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1628</link>
			<pubDate>Mon, 25 Jul 2022 10:17:56 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4010">suruena</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1628</guid>
			<description><![CDATA[The Rule 11.3 (category Required) disallows the conversion between two pointers to different object types, indicating in the first paragraph the possible problems due to different alignment, and in the second paragraph that even if same alignment it is undefined behavior anyway (citing C99 section 6.5p7), except if conversion to pointer to a char type.<br />
<br />
Even if the rule is technically correct, in my opinion readers will normally focus on the first paragraph, just analysing the alignment restrictions (and endianness) of the specific platform for justifying specific deviations (like using type punning through pointer conversion for needed format conversions). For example, justifying the conversion of a uint32_t into an array of two uint16_t, or a 32-bit float into a uint32_t. However, the part about undefined behavior is probably not highlighted enough, specially now that current compilers will take advantage of this undefined behavior to generate broken code due to the type aliasing analysis (reordering assignments or even removing code as the compiler is not required to consider the dependencies between those objects due to the undefined behavior, unless aliasing through a char pointer type or due to a few other exceptions).<br />
<br />
I think it would be much more useful for the reader to mention the "strict aliasing rule" (as this is the term normally used to warn about these problems in technical forums) and the possibility to get "miscompiled" code at high optimization levels. Also, I think it would be very appreciated to give some guidance of possible standard-compliant solutions like using memcpy instead (moreover as the compiler will probably remove the call overhead if optimizations enabled), copying into an union (which may also be optimized by the compiler, not really generating any data copy) if the compiler is compliant with C99 T3, or even disabling the strict aliasing when compiling (like using -fno-strict-aliasing in GCC), in addition to the already mentioned access through a pointer to a char type.  Even if it cannot be ensured the universal adequacy of these solutions, the readers will be warned about sophisticated compilers and the strict aliasing rule, and will be aware about possible solutions available to be considered in their specific platform. Thank you very much.<br />
<br />
Best regards,<br />
Santiago]]></description>
			<content:encoded><![CDATA[The Rule 11.3 (category Required) disallows the conversion between two pointers to different object types, indicating in the first paragraph the possible problems due to different alignment, and in the second paragraph that even if same alignment it is undefined behavior anyway (citing C99 section 6.5p7), except if conversion to pointer to a char type.<br />
<br />
Even if the rule is technically correct, in my opinion readers will normally focus on the first paragraph, just analysing the alignment restrictions (and endianness) of the specific platform for justifying specific deviations (like using type punning through pointer conversion for needed format conversions). For example, justifying the conversion of a uint32_t into an array of two uint16_t, or a 32-bit float into a uint32_t. However, the part about undefined behavior is probably not highlighted enough, specially now that current compilers will take advantage of this undefined behavior to generate broken code due to the type aliasing analysis (reordering assignments or even removing code as the compiler is not required to consider the dependencies between those objects due to the undefined behavior, unless aliasing through a char pointer type or due to a few other exceptions).<br />
<br />
I think it would be much more useful for the reader to mention the "strict aliasing rule" (as this is the term normally used to warn about these problems in technical forums) and the possibility to get "miscompiled" code at high optimization levels. Also, I think it would be very appreciated to give some guidance of possible standard-compliant solutions like using memcpy instead (moreover as the compiler will probably remove the call overhead if optimizations enabled), copying into an union (which may also be optimized by the compiler, not really generating any data copy) if the compiler is compliant with C99 T3, or even disabling the strict aliasing when compiling (like using -fno-strict-aliasing in GCC), in addition to the already mentioned access through a pointer to a char type.  Even if it cannot be ensured the universal adequacy of these solutions, the readers will be warned about sophisticated compilers and the strict aliasing rule, and will be aware about possible solutions available to be considered in their specific platform. Thank you very much.<br />
<br />
Best regards,<br />
Santiago]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 11.6. A cast between pointer to void and an arithmetic type. Value of the rule.]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1453</link>
			<pubDate>Thu, 06 Sep 2018 12:18:04 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5112">l.inc</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1453</guid>
			<description><![CDATA[Good day. To analyze a finding supported by this rule in a project I'd like to understand the intention of the rule. Specifically, in the context of C99 I fail to find an appropriate rationale to disallow converting between <span style="font-style: italic;" class="mycode_i">intptr_t</span>/<span style="font-style: italic;" class="mycode_i">uintptr_t</span> and <span style="font-style: italic;" class="mycode_i">void *</span>:<br />
<br />
<ol type="1" class="mycode_list"><li><blockquote class="mycode_quote"><cite>Quote:</cite>Conversion of an integer into a pointer to void may result in a pointer that is not correctly aligned, resulting in undefined behaviour.</blockquote>
Would you, please, explain how this rationale is compatible with the following statement in the C90/C99 standards:<br />
<blockquote class="mycode_quote"><cite>C99. 6.2.5 Types. Â§27 Wrote:</cite>A pointer to void shall have the same representation and alignment requirements as a pointer to a character type.</blockquote>As character pointers contain addresses of individual bytes, they cannot be unaligned. Hence pointers to <span style="font-style: italic;" class="mycode_i">void</span> cannot be unaligned too, right?<br />
Moreover, for the cases, in which the alignment problem indeed may occur, the restriction you define (rule 11.4) is, in contrast to 11.6, only advisory.<br />
</li>
<li><blockquote class="mycode_quote"><cite>Quote:</cite>Conversion of a pointer to void into an integer may produce a value that cannot be represented in the chosen integer type resulting in undefined behaviour.</blockquote>
This rationale does not apply to <span style="font-style: italic;" class="mycode_i">intptr_t</span>/<span style="font-style: italic;" class="mycode_i">uintptr_t</span>.<br />
</li>
<li><blockquote class="mycode_quote"><cite>Quote:</cite>Conversion between any non-integer arithmetic type and pointer to void is undefined.</blockquote>
This rationale looks like it would deserve a separate rule, as the limitations of these conversions for integers and non-integer arithmetic types are very different.</li>
</ol>
<br />
In addition to failing to find an appropriate rationale for disallowing conversions between <span style="font-style: italic;" class="mycode_i">intptr_t</span>/<span style="font-style: italic;" class="mycode_i">uintptr_t</span> and <span style="font-style: italic;" class="mycode_i">void *</span> I see positive value in favoring these over conversions between <span style="font-style: italic;" class="mycode_i">intptr_t</span>/<span style="font-style: italic;" class="mycode_i">uintptr_t</span> and object pointers. One advantage is the above mentioned alignment, but also that holding addresses as pointers to void prevents accidental accesses to the object. The more specific case of mine is when pointers to objects are produced by de-serialization (for which <span style="font-style: italic;" class="mycode_i">uintptr_t</span> is the most preferred type) and the objects are used nearly nowhere in the program but in copy operations via <span style="font-style: italic;" class="mycode_i">memcpy</span>. Improving compliance with MISRA C:2012 requires to convert the value into an object pointer first, which creates the risk of accidental dereferencing in the code, and only then into a pointer to <span style="font-style: italic;" class="mycode_i">void</span> to pass the value to <span style="font-style: italic;" class="mycode_i">memcpy</span>. This allows to trade a deviation from the required rule 11.6 for the deviation of the advisory rule 11.4. But at the same time the code then seems to become less safe.<br />
<br />
So were the conversions between <span style="font-style: italic;" class="mycode_i">intptr_t</span>/<span style="font-style: italic;" class="mycode_i">uintptr_t</span> and <span style="font-style: italic;" class="mycode_i">void *</span> disallowed unintentionally or do I just miss a safer way to handle the above described situations than to deviate from 11.6?]]></description>
			<content:encoded><![CDATA[Good day. To analyze a finding supported by this rule in a project I'd like to understand the intention of the rule. Specifically, in the context of C99 I fail to find an appropriate rationale to disallow converting between <span style="font-style: italic;" class="mycode_i">intptr_t</span>/<span style="font-style: italic;" class="mycode_i">uintptr_t</span> and <span style="font-style: italic;" class="mycode_i">void *</span>:<br />
<br />
<ol type="1" class="mycode_list"><li><blockquote class="mycode_quote"><cite>Quote:</cite>Conversion of an integer into a pointer to void may result in a pointer that is not correctly aligned, resulting in undefined behaviour.</blockquote>
Would you, please, explain how this rationale is compatible with the following statement in the C90/C99 standards:<br />
<blockquote class="mycode_quote"><cite>C99. 6.2.5 Types. Â§27 Wrote:</cite>A pointer to void shall have the same representation and alignment requirements as a pointer to a character type.</blockquote>As character pointers contain addresses of individual bytes, they cannot be unaligned. Hence pointers to <span style="font-style: italic;" class="mycode_i">void</span> cannot be unaligned too, right?<br />
Moreover, for the cases, in which the alignment problem indeed may occur, the restriction you define (rule 11.4) is, in contrast to 11.6, only advisory.<br />
</li>
<li><blockquote class="mycode_quote"><cite>Quote:</cite>Conversion of a pointer to void into an integer may produce a value that cannot be represented in the chosen integer type resulting in undefined behaviour.</blockquote>
This rationale does not apply to <span style="font-style: italic;" class="mycode_i">intptr_t</span>/<span style="font-style: italic;" class="mycode_i">uintptr_t</span>.<br />
</li>
<li><blockquote class="mycode_quote"><cite>Quote:</cite>Conversion between any non-integer arithmetic type and pointer to void is undefined.</blockquote>
This rationale looks like it would deserve a separate rule, as the limitations of these conversions for integers and non-integer arithmetic types are very different.</li>
</ol>
<br />
In addition to failing to find an appropriate rationale for disallowing conversions between <span style="font-style: italic;" class="mycode_i">intptr_t</span>/<span style="font-style: italic;" class="mycode_i">uintptr_t</span> and <span style="font-style: italic;" class="mycode_i">void *</span> I see positive value in favoring these over conversions between <span style="font-style: italic;" class="mycode_i">intptr_t</span>/<span style="font-style: italic;" class="mycode_i">uintptr_t</span> and object pointers. One advantage is the above mentioned alignment, but also that holding addresses as pointers to void prevents accidental accesses to the object. The more specific case of mine is when pointers to objects are produced by de-serialization (for which <span style="font-style: italic;" class="mycode_i">uintptr_t</span> is the most preferred type) and the objects are used nearly nowhere in the program but in copy operations via <span style="font-style: italic;" class="mycode_i">memcpy</span>. Improving compliance with MISRA C:2012 requires to convert the value into an object pointer first, which creates the risk of accidental dereferencing in the code, and only then into a pointer to <span style="font-style: italic;" class="mycode_i">void</span> to pass the value to <span style="font-style: italic;" class="mycode_i">memcpy</span>. This allows to trade a deviation from the required rule 11.6 for the deviation of the advisory rule 11.4. But at the same time the code then seems to become less safe.<br />
<br />
So were the conversions between <span style="font-style: italic;" class="mycode_i">intptr_t</span>/<span style="font-style: italic;" class="mycode_i">uintptr_t</span> and <span style="font-style: italic;" class="mycode_i">void *</span> disallowed unintentionally or do I just miss a safer way to handle the above described situations than to deviate from 11.6?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 11.9: Does this struct initialization violate rule 11.9?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1371</link>
			<pubDate>Wed, 27 Sep 2017 10:09:47 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4863">fst-mra</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1371</guid>
			<description><![CDATA[Dear community,<br />
<br />
our analysis tool reports the following struct initialization to violate rule 11.9 (macro NULL is the only permitted form of integer null pointer constant): <br />
<br />
static const myType myStruct = { <br />
    64, <br />
    {0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0}, <br />
    0 <br />
}; <br />
<br />
with:<br />
typedef unsigned short uint16;<br />
typedef unsigned char uint8;<br />
 typedef struct { <br />
    uint16 myVariable01;<br />
    uint8  myArray [16];<br />
    uint8  myVariable02; <br />
} myType; <br />
<br />
Unfortunately, neither from the tool documentation nor from the MISRA documentation we can conclude why this initialization would be non-compliant. Also we cannot see what the risk behind this deviation would be. Is this deviation false-positive? Does it introduce any portability, maintainability etc. risk?<br />
<br />
Thanks for your support.<br />
Frank]]></description>
			<content:encoded><![CDATA[Dear community,<br />
<br />
our analysis tool reports the following struct initialization to violate rule 11.9 (macro NULL is the only permitted form of integer null pointer constant): <br />
<br />
static const myType myStruct = { <br />
    64, <br />
    {0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0}, <br />
    0 <br />
}; <br />
<br />
with:<br />
typedef unsigned short uint16;<br />
typedef unsigned char uint8;<br />
 typedef struct { <br />
    uint16 myVariable01;<br />
    uint8  myArray [16];<br />
    uint8  myVariable02; <br />
} myType; <br />
<br />
Unfortunately, neither from the tool documentation nor from the MISRA documentation we can conclude why this initialization would be non-compliant. Also we cannot see what the risk behind this deviation would be. Is this deviation false-positive? Does it introduce any portability, maintainability etc. risk?<br />
<br />
Thanks for your support.<br />
Frank]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 11.9: Does array initialization to 0 violate Rule 11.9?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1370</link>
			<pubDate>Wed, 27 Sep 2017 10:00:38 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4863">fst-mra</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1370</guid>
			<description><![CDATA[Dear community,<br />
<br />
our analysis tool reports the following array initialization to violate rule 11.9 (macro NULL is the only permitted form of integer null pointer constant): <br />
<br />
uint8 myBuffer[8] = {0u}; // with "typedef unsigned char uint8;"<br />
<br />
Unfortunately, neither from the tool documentation nor from the MISRA documentation we can conclude why this "standard" construct would be non-compliant. Also we cannot see what the risk behind this deviation would be. Is this deviation false-positive? Does it introduce any portability, maintainability etc. risk?<br />
<br />
Thanks for your support.<br />
Frank]]></description>
			<content:encoded><![CDATA[Dear community,<br />
<br />
our analysis tool reports the following array initialization to violate rule 11.9 (macro NULL is the only permitted form of integer null pointer constant): <br />
<br />
uint8 myBuffer[8] = {0u}; // with "typedef unsigned char uint8;"<br />
<br />
Unfortunately, neither from the tool documentation nor from the MISRA documentation we can conclude why this "standard" construct would be non-compliant. Also we cannot see what the risk behind this deviation would be. Is this deviation false-positive? Does it introduce any portability, maintainability etc. risk?<br />
<br />
Thanks for your support.<br />
Frank]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 11.3 pointer to array of const element]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1333</link>
			<pubDate>Thu, 06 Apr 2017 13:55:26 +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=1333</guid>
			<description><![CDATA[<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>static void use_array(uint8_t const (* const arr)[4])<br />
{<br />
}<br />
<br />
int main()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;uint8_t aAction[4] = {0, 0, 0, 0};<br />
&nbsp;&nbsp;&nbsp;&nbsp;use_array((uint8_t const(*)[4]) &amp;aAction); // 11.3 violation?<br />
}</code></div></div><br />
As I read rule 11.3, the cast in the use_array call violates rule 11.3: the target type of the pointer is "4-element array of const uint8_t". Given that the "const" is not at top-level, adding it is not permitted by this rule.<br />
<br />
However, that raises the question: how can I call use_array() from Misra-compliant code?<br />
<br />
Note that the cast is required by ISO C (gcc says: pointers to arrays with different qualifiers are incompatible in ISO C [-Wpedantic]).<br />
However, in C++, an implicit conversion exists for this case.]]></description>
			<content:encoded><![CDATA[<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>static void use_array(uint8_t const (* const arr)[4])<br />
{<br />
}<br />
<br />
int main()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;uint8_t aAction[4] = {0, 0, 0, 0};<br />
&nbsp;&nbsp;&nbsp;&nbsp;use_array((uint8_t const(*)[4]) &amp;aAction); // 11.3 violation?<br />
}</code></div></div><br />
As I read rule 11.3, the cast in the use_array call violates rule 11.3: the target type of the pointer is "4-element array of const uint8_t". Given that the "const" is not at top-level, adding it is not permitted by this rule.<br />
<br />
However, that raises the question: how can I call use_array() from Misra-compliant code?<br />
<br />
Note that the cast is required by ISO C (gcc says: pointers to arrays with different qualifiers are incompatible in ISO C [-Wpedantic]).<br />
However, in C++, an implicit conversion exists for this case.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA["null pointer constant"?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1324</link>
			<pubDate>Wed, 08 Mar 2017 23:06:02 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=3355">swestin</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1324</guid>
			<description><![CDATA[The MISRA C:2012 guidelines (p. 93) define a "null pointer constant" as<br />
<br />
     the value 0, optionally cast to void *<br />
<br />
Does this allow floating-point zero as a null pointer constant, e. g.<br />
<br />
    int32_t * pint = (void*)0.0f;<br />
<br />
That seems crazy to me, but Rule 11.4 specifically allows a "null pointer constant that has integer type", whereas other mentions (Rules 11.1 and 11.2) omit "integer".<br />
<br />
Was the intent to specify an <span style="font-style: italic;" class="mycode_i">integer</span> zero?]]></description>
			<content:encoded><![CDATA[The MISRA C:2012 guidelines (p. 93) define a "null pointer constant" as<br />
<br />
     the value 0, optionally cast to void *<br />
<br />
Does this allow floating-point zero as a null pointer constant, e. g.<br />
<br />
    int32_t * pint = (void*)0.0f;<br />
<br />
That seems crazy to me, but Rule 11.4 specifically allows a "null pointer constant that has integer type", whereas other mentions (Rules 11.1 and 11.2) omit "integer".<br />
<br />
Was the intent to specify an <span style="font-style: italic;" class="mycode_i">integer</span> zero?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 11.8: non-compatible pointees]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1304</link>
			<pubDate>Thu, 05 Jan 2017 16:58:31 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=815">pmhill</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1304</guid>
			<description><![CDATA[In the following code I would like to know which of the casts are compliant for rule 11.8?<br />
<br />
[code]<br />
const int a[10];<br />
int *pi;<br />
int **ppi;<br />
const int **cppi;<br />
const float **cppf;<br />
<br />
void f() {<br />
  pi = (int*) &amp;a; /* int * ]]></description>
			<content:encoded><![CDATA[In the following code I would like to know which of the casts are compliant for rule 11.8?<br />
<br />
[code]<br />
const int a[10];<br />
int *pi;<br />
int **ppi;<br />
const int **cppi;<br />
const float **cppf;<br />
<br />
void f() {<br />
  pi = (int*) &amp;a; /* int * ]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Does Rule 11.9 allow indirect expansion from NULL?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1272</link>
			<pubDate>Wed, 14 Sep 2016 14:23:14 +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=1272</guid>
			<description><![CDATA[Does the following example violate Rule 11.9?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define FOO NULL<br />
int32_t *p1 = FOO;</code></div></div>]]></description>
			<content:encoded><![CDATA[Does the following example violate Rule 11.9?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define FOO NULL<br />
int32_t *p1 = FOO;</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[11.3 - char * to uint8_t *]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1238</link>
			<pubDate>Wed, 27 Apr 2016 11:05:01 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4245">delta_controls</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1238</guid>
			<description><![CDATA[In the following example there is an implicit conversion from (char *) to (uint8_t *):<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>extern void print(const uint8_t *text);<br />
<br />
int main(void)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;print("Some text");<br />
}</code></div></div><br />
Am I correct in thinking that this is compliant?  Or does the exception to rule 11.3 only apply when conversions are explicit?<br />
<br />
Thanks.]]></description>
			<content:encoded><![CDATA[In the following example there is an implicit conversion from (char *) to (uint8_t *):<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>extern void print(const uint8_t *text);<br />
<br />
int main(void)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;print("Some text");<br />
}</code></div></div><br />
Am I correct in thinking that this is compliant?  Or does the exception to rule 11.3 only apply when conversions are explicit?<br />
<br />
Thanks.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Unclear why this code is not compliant with rule 11.3]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1197</link>
			<pubDate>Tue, 04 Aug 2015 21:00:00 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=3976">m4l490n</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1197</guid>
			<description><![CDATA[Hi everybody<br />
<br />
I'm having a very hard time understanding why the following code gives me two errors regarding rule 11.3.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define NUM_TASKS 3<br />
<br />
typedef struct<br />
{<br />
&nbsp;&nbsp;uint32_t *CpuUtilizationPercent;<br />
&nbsp;&nbsp;uint32_t *Counter;<br />
&nbsp;&nbsp;TaskParam_t *Params;<br />
&nbsp;&nbsp;TaskConfig_t *Tasks;<br />
&nbsp;&nbsp;uint8_t NumTasks;<br />
} PPTS_Config_t;<br />
<br />
static uint32_t PPTS_CpuUtilizationPercent;<br />
static uint32_t PPTS_Counter;<br />
<br />
static TaskParam_t TaskParams[NUM_TASKS];<br />
<br />
static TaskConfig_t TaskConfig[NUM_TASKS];<br />
<br />
const PPTS_Config_t CnfPPTS =<br />
{<br />
&nbsp;&nbsp;&amp;PPTS_CpuUtilizationPercent,<br />
&nbsp;&nbsp;&amp;PPTS_Counter,<br />
&nbsp;&nbsp;TaskParams,&nbsp;&nbsp;/* MISRA-C rule 11.3 violation */<br />
&nbsp;&nbsp;TaskConfig,&nbsp;&nbsp; /* MISRA-C rule 11.3 violation */<br />
&nbsp;&nbsp;NUM_TASKS<br />
};</code></div></div>And in both cases the error is: <span style="font-weight: bold;" class="mycode_b">A cast shall not be performed between a pointer to object type and a pointer to a different object type</span><br />
<br />
The thing here is that both <span style="font-weight: bold;" class="mycode_b">TaskParams</span> and <span style="font-weight: bold;" class="mycode_b">TaskConfig</span> are pointers of the same type that are the struct elements <span style="font-weight: bold;" class="mycode_b">Params</span> and <span style="font-weight: bold;" class="mycode_b">Tasks</span>. I don't understand how ---<span style="font-style: italic;" class="mycode_i"><span style="font-weight: bold;" class="mycode_b">TaskConfig_t</span> TaskConfig[NUM_TASKS]</span>--- is different from ---<span style="font-style: italic;" class="mycode_i"><span style="font-weight: bold;" class="mycode_b">TaskConfig_t</span> *Tasks</span>---. They seem similar to me, or, am I messign something?<br />
<br />
Thank you very much for helping and I hope this could be explained because I'm really frustrated.<br />
<br />
Regards.]]></description>
			<content:encoded><![CDATA[Hi everybody<br />
<br />
I'm having a very hard time understanding why the following code gives me two errors regarding rule 11.3.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define NUM_TASKS 3<br />
<br />
typedef struct<br />
{<br />
&nbsp;&nbsp;uint32_t *CpuUtilizationPercent;<br />
&nbsp;&nbsp;uint32_t *Counter;<br />
&nbsp;&nbsp;TaskParam_t *Params;<br />
&nbsp;&nbsp;TaskConfig_t *Tasks;<br />
&nbsp;&nbsp;uint8_t NumTasks;<br />
} PPTS_Config_t;<br />
<br />
static uint32_t PPTS_CpuUtilizationPercent;<br />
static uint32_t PPTS_Counter;<br />
<br />
static TaskParam_t TaskParams[NUM_TASKS];<br />
<br />
static TaskConfig_t TaskConfig[NUM_TASKS];<br />
<br />
const PPTS_Config_t CnfPPTS =<br />
{<br />
&nbsp;&nbsp;&amp;PPTS_CpuUtilizationPercent,<br />
&nbsp;&nbsp;&amp;PPTS_Counter,<br />
&nbsp;&nbsp;TaskParams,&nbsp;&nbsp;/* MISRA-C rule 11.3 violation */<br />
&nbsp;&nbsp;TaskConfig,&nbsp;&nbsp; /* MISRA-C rule 11.3 violation */<br />
&nbsp;&nbsp;NUM_TASKS<br />
};</code></div></div>And in both cases the error is: <span style="font-weight: bold;" class="mycode_b">A cast shall not be performed between a pointer to object type and a pointer to a different object type</span><br />
<br />
The thing here is that both <span style="font-weight: bold;" class="mycode_b">TaskParams</span> and <span style="font-weight: bold;" class="mycode_b">TaskConfig</span> are pointers of the same type that are the struct elements <span style="font-weight: bold;" class="mycode_b">Params</span> and <span style="font-weight: bold;" class="mycode_b">Tasks</span>. I don't understand how ---<span style="font-style: italic;" class="mycode_i"><span style="font-weight: bold;" class="mycode_b">TaskConfig_t</span> TaskConfig[NUM_TASKS]</span>--- is different from ---<span style="font-style: italic;" class="mycode_i"><span style="font-weight: bold;" class="mycode_b">TaskConfig_t</span> *Tasks</span>---. They seem similar to me, or, am I messign something?<br />
<br />
Thank you very much for helping and I hope this could be explained because I'm really frustrated.<br />
<br />
Regards.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Does constness count as a type difference in rule 11.2?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1196</link>
			<pubDate>Thu, 23 Jul 2015 15:55:09 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=307">fpeelo</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1196</guid>
			<description><![CDATA[I have an incomplete struct type, as per Directive 4.8. I declare types for pointers to the hidden struct:<br />
<br />
typedef struct s_EthBuf *TEthBuf;<br />
typedef struct s_EthBuf const *CTEthBuf;<br />
<br />
The actual type, and an instance of the type, are declared in the translation unit that also defines the functions which operate on it.<br />
<br />
Some functions need to modify the contents of the object, so they take a parameter of type TEthBuf. Some do not; they take a parameter of type CTEthBuf.<br />
<br />
PC-Lint tells me that assigning a TEthBuf pointer to a variable of type CTEthBuf, or const TEthBuf, or passing it to a function which takes CTEthBuf as its parameter type, violates rule 11.2.<br />
<br />
So: if I have struct s_EthBuf X then the following get the warning the 11.2 is violated:<br />
  CTEthBuf a = X; <br />
  const TEthBuf b = X;<br />
  foo(x) <br />
    - where foo is declared as void foo(CTEthBuf buf);<br />
<br />
But it's OK to do<br />
  TEthBuf c = X;<br />
<br />
But the type is the same, it's just that foo() doesn't change anything in the object.<br />
<br />
Is PC-Lint correct here, when it believes that the types are different from the point of view of rule 11.2?]]></description>
			<content:encoded><![CDATA[I have an incomplete struct type, as per Directive 4.8. I declare types for pointers to the hidden struct:<br />
<br />
typedef struct s_EthBuf *TEthBuf;<br />
typedef struct s_EthBuf const *CTEthBuf;<br />
<br />
The actual type, and an instance of the type, are declared in the translation unit that also defines the functions which operate on it.<br />
<br />
Some functions need to modify the contents of the object, so they take a parameter of type TEthBuf. Some do not; they take a parameter of type CTEthBuf.<br />
<br />
PC-Lint tells me that assigning a TEthBuf pointer to a variable of type CTEthBuf, or const TEthBuf, or passing it to a function which takes CTEthBuf as its parameter type, violates rule 11.2.<br />
<br />
So: if I have struct s_EthBuf X then the following get the warning the 11.2 is violated:<br />
  CTEthBuf a = X; <br />
  const TEthBuf b = X;<br />
  foo(x) <br />
    - where foo is declared as void foo(CTEthBuf buf);<br />
<br />
But it's OK to do<br />
  TEthBuf c = X;<br />
<br />
But the type is the same, it's just that foo() doesn't change anything in the object.<br />
<br />
Is PC-Lint correct here, when it believes that the types are different from the point of view of rule 11.2?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 11.1, 11.2 (and others?) vs conversion caused by equality operators (and similar)?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1184</link>
			<pubDate>Wed, 03 Jun 2015 14:14:05 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=368">pkruk</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1184</guid>
			<description><![CDATA[Hello,<br />
<br />
rules 11.1 and 11.2 disallow conversions between pointer to a function or incomplete type, and any other type:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void (*fp1)(short);<br />
void (*fp2)(int);<br />
<br />
fp2 = fp1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Not-compliant - different function */<br />
fp2 = 0x8000;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Not-compliant - integer */</code></div></div><br />
What if the conversion happens for example in equality operator:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>fp2 == fp1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Compliant or Not-compliant ? */<br />
fp2 != 0x8000;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant or Not-compliant ? */</code></div></div><br />
Following example from Rule 11.1 suggests it's also non-compliant:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>if ( fp2 != NULL )&nbsp;&nbsp;/* Compliant - exception 1 (NULL) */</code></div></div>]]></description>
			<content:encoded><![CDATA[Hello,<br />
<br />
rules 11.1 and 11.2 disallow conversions between pointer to a function or incomplete type, and any other type:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void (*fp1)(short);<br />
void (*fp2)(int);<br />
<br />
fp2 = fp1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Not-compliant - different function */<br />
fp2 = 0x8000;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Not-compliant - integer */</code></div></div><br />
What if the conversion happens for example in equality operator:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>fp2 == fp1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Compliant or Not-compliant ? */<br />
fp2 != 0x8000;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Compliant or Not-compliant ? */</code></div></div><br />
Following example from Rule 11.1 suggests it's also non-compliant:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>if ( fp2 != NULL )&nbsp;&nbsp;/* Compliant - exception 1 (NULL) */</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Example at 11.1 and 11.2]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1177</link>
			<pubDate>Wed, 29 Apr 2015 09:24:31 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=114">ogawa.kiyoshi</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1177</guid>
			<description><![CDATA[In example codes in Rule 11.1 and Rule 11.2<br />
<br />
#include   /* to obtain macro NULL */<br />
<br />
in example codes in 11.9<br />
<br />
#include <br />
<br />
A freestanding environment needs stdarg.h not sodlib.h.<br />
So I prefer to obtain macro NULL, <br />
#include  // to obtain macro NULL<br />
<br />
Is it reasonable?<br />
<br />
ps. in 11.9 <br />
/* Could also be stdio.h, stdlib.h and others */<br />
<br />
I prefer<br />
/* A free standing environment needs stddef.h */<br />
/* Could also be stdio.h, stdlib.h and others in host environments */<br />
<br />
Best Regards.]]></description>
			<content:encoded><![CDATA[In example codes in Rule 11.1 and Rule 11.2<br />
<br />
#include   /* to obtain macro NULL */<br />
<br />
in example codes in 11.9<br />
<br />
#include <br />
<br />
A freestanding environment needs stdarg.h not sodlib.h.<br />
So I prefer to obtain macro NULL, <br />
#include  // to obtain macro NULL<br />
<br />
Is it reasonable?<br />
<br />
ps. in 11.9 <br />
/* Could also be stdio.h, stdlib.h and others */<br />
<br />
I prefer<br />
/* A free standing environment needs stddef.h */<br />
/* Could also be stdio.h, stdlib.h and others in host environments */<br />
<br />
Best Regards.]]></content:encoded>
		</item>
	</channel>
</rss>