<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title><![CDATA[MISRA Discussion Forums - 6.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 15:13:30 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[Rule 11.3 Access to registers or memory]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1042</link>
			<pubDate>Thu, 27 Mar 2014 10:31:25 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=2908">barbara.seyfarth</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1042</guid>
			<description><![CDATA[A cast should not be performed between a pointer type and an integral type, this casts from type "unsigned int" to "uint32_t volatile *"  (MISRA C 2004 rule 11.3) <br />
In two cases this error occurs on my system (ARM Cortex M3 with IAR workbench and MISRA check from IAR):<br />
1. Access to registers.<br />
2. Access to RAM (during a cyclic RAM test).<br />
<br />
Is there any way conform to MISRA C2004 for the following code?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>register uint32_t address; /* during the critical section no RAM access other than the test access may occur */<br />
&nbsp;&nbsp;&nbsp;&nbsp;register uint32_t pattern;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
&nbsp;&nbsp;&nbsp;&nbsp;*(volatile uint32_t *)address = pattern;</code></div></div>]]></description>
			<content:encoded><![CDATA[A cast should not be performed between a pointer type and an integral type, this casts from type "unsigned int" to "uint32_t volatile *"  (MISRA C 2004 rule 11.3) <br />
In two cases this error occurs on my system (ARM Cortex M3 with IAR workbench and MISRA check from IAR):<br />
1. Access to registers.<br />
2. Access to RAM (during a cyclic RAM test).<br />
<br />
Is there any way conform to MISRA C2004 for the following code?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>register uint32_t address; /* during the critical section no RAM access other than the test access may occur */<br />
&nbsp;&nbsp;&nbsp;&nbsp;register uint32_t pattern;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
&nbsp;&nbsp;&nbsp;&nbsp;*(volatile uint32_t *)address = pattern;</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[MISRA 11.2]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=958</link>
			<pubDate>Wed, 10 Apr 2013 09:36:49 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=2595">spd123</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=958</guid>
			<description><![CDATA[Hi,<br />
<br />
[ MISRA 11.2 ] Conversions shall not be performed between a pointer to object and any type, other than an integral type, another pointer to object type or a pointer to void.<br />
<br />
I am using cystal revs for C MISRA C 2004 compliance.<br />
Its showing violation in following code. pl. suggest solution for this. <br />
cal_table F32 xdata cal_table[10];<br />
here F32 is float.<br />
<br />
Main.c<br />
--------------<br />
*( ( ( U8 * )&amp;cal_table[ 0 ] ) + 0U ) = 0U;   <br />
<br />
if( ( command_str[ 2 ] == SNS_ID1 ) &amp;&amp; ( command_str[ 3 ] == SNS_ID1 ) ) // SNS_ID1 is constant<br />
<br />
*( ( ( U8 * )&amp;cal_table[ i ] ) + ch ) = ASCII_Int( command_str + 10U, 3U );<br />
<br />
ch = *( ( ( U8 * )&amp;cal_table[ i ] ) + ch );<br />
<br />
spi_write( ( U8 )AX5031_REG_PLLLOOP, ( U8 )AX5031_VAL_PLLLOOP ); //AX5031_REG_PLLLOOP &amp; AX5031_VAL_PLLLOOP are constats.]]></description>
			<content:encoded><![CDATA[Hi,<br />
<br />
[ MISRA 11.2 ] Conversions shall not be performed between a pointer to object and any type, other than an integral type, another pointer to object type or a pointer to void.<br />
<br />
I am using cystal revs for C MISRA C 2004 compliance.<br />
Its showing violation in following code. pl. suggest solution for this. <br />
cal_table F32 xdata cal_table[10];<br />
here F32 is float.<br />
<br />
Main.c<br />
--------------<br />
*( ( ( U8 * )&amp;cal_table[ 0 ] ) + 0U ) = 0U;   <br />
<br />
if( ( command_str[ 2 ] == SNS_ID1 ) &amp;&amp; ( command_str[ 3 ] == SNS_ID1 ) ) // SNS_ID1 is constant<br />
<br />
*( ( ( U8 * )&amp;cal_table[ i ] ) + ch ) = ASCII_Int( command_str + 10U, 3U );<br />
<br />
ch = *( ( ( U8 * )&amp;cal_table[ i ] ) + ch );<br />
<br />
spi_write( ( U8 )AX5031_REG_PLLLOOP, ( U8 )AX5031_VAL_PLLLOOP ); //AX5031_REG_PLLLOOP &amp; AX5031_VAL_PLLLOOP are constats.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Pointer conversions (implicit, explicit, void)]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=901</link>
			<pubDate>Fri, 25 May 2012 16:19:26 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=2090">Gabe</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=901</guid>
			<description><![CDATA[I would like to ask for some help interpreting MISRA-C:2004. I have a few very simple examples. Please confirm whether my observations below are correct.<br />
<br />
1)<br />
#include <br />
void main(void) {<br />
  char* string = "Hello World!";<br />
  int* result = string;<br />
  printf("Result: %d\n", *result);<br />
}<br />
<br />
This code is not MISRA-C:2004 compliant, because the implicit pointer conversion is not legal ANSI C. Thus, it violates rule 1.1. Is this observation correct?<br />
<br />
2)<br />
#include <br />
void main(void) {<br />
  char* string = "Hello World!";<br />
  int* result = (int*)string;<br />
  printf("Result: %d\n", *result);<br />
}<br />
<br />
This code is MISRA-C:2004 compliant. However, the explicit type cast to int* is a violation of advisory rule 11.4. Is this observation correct?<br />
<br />
3)<br />
#include <br />
void main(void) {<br />
  char* string = "Hello World!";<br />
  void* void_ptr = string;<br />
  int* result = void_ptr;<br />
  printf("Result: %d\n", *result);<br />
}<br />
<br />
This code is MISRA-C:2004 compliant. It also does not violate advisory rule 11.4. Is this observation correct?<br />
<br />
4)<br />
#include <br />
void main(void) {<br />
  char* string = "Hello World!";<br />
  void* void_ptr = (void*)string;<br />
  int* result = void_ptr;<br />
  printf("Result: %d\n", *result);<br />
}<br />
<br />
This code is MISRA-C:2004 compliant. However, it now does violate advisory rule 11.4 due to the use of the type cast operator. Is this observation correct?<br />
<br />
I do not see how 3) is better than alternative 2) or 4) above. Double casting through void pointers does not seem to be safe practice. It hides the conversion intent, so it makes the code harder to read.<br />
<br />
I understand that the main reason for allowing conversions to void pointers is due to legacy reasons (i.e. writing data to memory). Seeing that 11.4 is advisory, would it not be better to refer to "conversions" between different pointers to object, rather than "casting"?]]></description>
			<content:encoded><![CDATA[I would like to ask for some help interpreting MISRA-C:2004. I have a few very simple examples. Please confirm whether my observations below are correct.<br />
<br />
1)<br />
#include <br />
void main(void) {<br />
  char* string = "Hello World!";<br />
  int* result = string;<br />
  printf("Result: %d\n", *result);<br />
}<br />
<br />
This code is not MISRA-C:2004 compliant, because the implicit pointer conversion is not legal ANSI C. Thus, it violates rule 1.1. Is this observation correct?<br />
<br />
2)<br />
#include <br />
void main(void) {<br />
  char* string = "Hello World!";<br />
  int* result = (int*)string;<br />
  printf("Result: %d\n", *result);<br />
}<br />
<br />
This code is MISRA-C:2004 compliant. However, the explicit type cast to int* is a violation of advisory rule 11.4. Is this observation correct?<br />
<br />
3)<br />
#include <br />
void main(void) {<br />
  char* string = "Hello World!";<br />
  void* void_ptr = string;<br />
  int* result = void_ptr;<br />
  printf("Result: %d\n", *result);<br />
}<br />
<br />
This code is MISRA-C:2004 compliant. It also does not violate advisory rule 11.4. Is this observation correct?<br />
<br />
4)<br />
#include <br />
void main(void) {<br />
  char* string = "Hello World!";<br />
  void* void_ptr = (void*)string;<br />
  int* result = void_ptr;<br />
  printf("Result: %d\n", *result);<br />
}<br />
<br />
This code is MISRA-C:2004 compliant. However, it now does violate advisory rule 11.4 due to the use of the type cast operator. Is this observation correct?<br />
<br />
I do not see how 3) is better than alternative 2) or 4) above. Double casting through void pointers does not seem to be safe practice. It hides the conversion intent, so it makes the code harder to read.<br />
<br />
I understand that the main reason for allowing conversions to void pointers is due to legacy reasons (i.e. writing data to memory). Seeing that 11.4 is advisory, would it not be better to refer to "conversions" between different pointers to object, rather than "casting"?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Pointer type conversions to char*]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=819</link>
			<pubDate>Thu, 24 Mar 2011 17:15:52 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=159">dcrocker</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=819</guid>
			<description><![CDATA[I have recently come across code similar to the following:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void serialize(const uint8 data[], size_t length);<br />
<br />
int16 myData;<br />
...<br />
serialize((const uint8*)&amp;myData, sizeof(myData));&nbsp;&nbsp;&nbsp;&nbsp;/* violates MISRA 11.4 */<br />
serialize((const void*)&amp;myData, sizeof(myData));&nbsp;&nbsp;&nbsp;&nbsp; /* obscures what is going on, but allowed by MISRA */</code></div></div><br />
It seems to me perverse that the first call violates a MISRA rule (even though casting any pointer to a char* does not give rise to alignment issues, see 6.3.4 in the standard), whereas the second contains a potentially dangerous implicit type conversion from void* to another pointer type (imagine that the parameter to serialize had been declared as "const uint32[]" instead).<br />
<br />
One possibility is to declare the parameter to serialize as having type const void* instead, but I'm not sure I like this, and it would be necessary to convert it to uint8* anyway inside serialize.<br />
<br />
I would prefer to see MISRA C3 amend the rules along the following lines:<br />
<br />
1. Explicit casts from an object pointer type to signed or unsigned char* are permitted;<br />
<br />
2. Implicit casts from void* to any other type are not permitted. [I don't understand why the MISRA standard ever allowed them.] <br />
<br />
3. Maybe a rule along the lines of "A pointer of type void* may only be converted to the same pointer type that it was originally derived from" (with the usual permission to add cv-qualifiers). Perhaps also permitting void* to be converted to signed/unsigned char*.<br />
<br />
Any comments?]]></description>
			<content:encoded><![CDATA[I have recently come across code similar to the following:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void serialize(const uint8 data[], size_t length);<br />
<br />
int16 myData;<br />
...<br />
serialize((const uint8*)&amp;myData, sizeof(myData));&nbsp;&nbsp;&nbsp;&nbsp;/* violates MISRA 11.4 */<br />
serialize((const void*)&amp;myData, sizeof(myData));&nbsp;&nbsp;&nbsp;&nbsp; /* obscures what is going on, but allowed by MISRA */</code></div></div><br />
It seems to me perverse that the first call violates a MISRA rule (even though casting any pointer to a char* does not give rise to alignment issues, see 6.3.4 in the standard), whereas the second contains a potentially dangerous implicit type conversion from void* to another pointer type (imagine that the parameter to serialize had been declared as "const uint32[]" instead).<br />
<br />
One possibility is to declare the parameter to serialize as having type const void* instead, but I'm not sure I like this, and it would be necessary to convert it to uint8* anyway inside serialize.<br />
<br />
I would prefer to see MISRA C3 amend the rules along the following lines:<br />
<br />
1. Explicit casts from an object pointer type to signed or unsigned char* are permitted;<br />
<br />
2. Implicit casts from void* to any other type are not permitted. [I don't understand why the MISRA standard ever allowed them.] <br />
<br />
3. Maybe a rule along the lines of "A pointer of type void* may only be converted to the same pointer type that it was originally derived from" (with the usual permission to add cv-qualifiers). Perhaps also permitting void* to be converted to signed/unsigned char*.<br />
<br />
Any comments?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 11.5 and char/string constants]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=799</link>
			<pubDate>Wed, 12 Jan 2011 16:36:26 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=1198">armand</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=799</guid>
			<description><![CDATA[Hi,<br />
<br />
Whilst testing my implementation of rule 4.2 with a simple example, I got a warning about rule 11.5. It is on the following simple example:<br />
<br />
void main() {<br />
  char * x="abcd";<br />
  return;<br />
}<br />
<br />
that is automatically translated by CIL into the following C code, where one can notice a new cast.<br />
<br />
void main() {<br />
  char *x;<br />
  x=(char *)"abcd";<br />
}<br />
<br />
the 11.5 warning concerns the assignment, where it complains that the attribute const has been lost.<br />
Indeed, the rhs expression has type const char *, so this seems normal.<br />
<br />
A correct writing would be:<br />
<br />
void main()  {<br />
  char *x;<br />
  char content[4]="abcd";<br />
  x=&amp;content[0];<br />
}<br />
which does not generate the 11.5 warning as we have well typed the constant and assigned the first element's address into x.<br />
BUT, now I get a warning about rule 9.2 explaining that I haven't a braced expression on the rhs of the assignement, to initialize the array!!<br />
<br />
I can correct this by decomposing "abcd" into {'a','b','c','d''} which removes the last warning but gets tedious.<br />
<br />
So my question is: does MISRA discourage programmers from using strings?]]></description>
			<content:encoded><![CDATA[Hi,<br />
<br />
Whilst testing my implementation of rule 4.2 with a simple example, I got a warning about rule 11.5. It is on the following simple example:<br />
<br />
void main() {<br />
  char * x="abcd";<br />
  return;<br />
}<br />
<br />
that is automatically translated by CIL into the following C code, where one can notice a new cast.<br />
<br />
void main() {<br />
  char *x;<br />
  x=(char *)"abcd";<br />
}<br />
<br />
the 11.5 warning concerns the assignment, where it complains that the attribute const has been lost.<br />
Indeed, the rhs expression has type const char *, so this seems normal.<br />
<br />
A correct writing would be:<br />
<br />
void main()  {<br />
  char *x;<br />
  char content[4]="abcd";<br />
  x=&amp;content[0];<br />
}<br />
which does not generate the 11.5 warning as we have well typed the constant and assigned the first element's address into x.<br />
BUT, now I get a warning about rule 9.2 explaining that I haven't a braced expression on the rhs of the assignement, to initialize the array!!<br />
<br />
I can correct this by decomposing "abcd" into {'a','b','c','d''} which removes the last warning but gets tedious.<br />
<br />
So my question is: does MISRA discourage programmers from using strings?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Pointer to function  conversions (11.1)]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=760</link>
			<pubDate>Wed, 28 Jul 2010 10:46:10 +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=760</guid>
			<description><![CDATA[Hello, <br />
<br />
rule 11.1 disallows conversions between function pointers and any other type than integral type.<br />
<br />
1. conversion between compatible function types - are they allowed? For example:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef struct S1 { int x; } TS1;<br />
struct S1 (*f1)();<br />
TS1 (*f2)();<br />
f1 = f2; // Is this compliant?</code></div></div>    <br />
<br />
2. what about following case?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>enum STYPE_LIST {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TYPEA,<br />
&nbsp;&nbsp;&nbsp;&nbsp;};<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;typedef int (*func_t)(char *);<br />
&nbsp;&nbsp;&nbsp;&nbsp;typedef STYPE_LIST (*func_t2)(char *);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;void moo() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;func_t p;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;func_t2 p2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p= (func_t)p2;&nbsp;&nbsp;// Is this compliant? Enum vs int<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</code></div></div>]]></description>
			<content:encoded><![CDATA[Hello, <br />
<br />
rule 11.1 disallows conversions between function pointers and any other type than integral type.<br />
<br />
1. conversion between compatible function types - are they allowed? For example:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef struct S1 { int x; } TS1;<br />
struct S1 (*f1)();<br />
TS1 (*f2)();<br />
f1 = f2; // Is this compliant?</code></div></div>    <br />
<br />
2. what about following case?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>enum STYPE_LIST {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TYPEA,<br />
&nbsp;&nbsp;&nbsp;&nbsp;};<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;typedef int (*func_t)(char *);<br />
&nbsp;&nbsp;&nbsp;&nbsp;typedef STYPE_LIST (*func_t2)(char *);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;void moo() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;func_t p;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;func_t2 p2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p= (func_t)p2;&nbsp;&nbsp;// Is this compliant? Enum vs int<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Violations of rules 11.1, 11.2, 11.3, 11.4]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=693</link>
			<pubDate>Wed, 25 Nov 2009 12:40:43 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=893">adytzul_ac</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=693</guid>
			<description><![CDATA[Hello.<br />
My PC-LINT tool gives me an error of violating of rules 11.1, 11.2, 11.3, 11.4 (cast from unsigned char to pointer ) on the line 2:<br />
<br />
line 1: unsigned char* ptr;<br />
line 2: ptr=(unsigned char*)0x12;<br />
<br />
The idea behind is that I want to initialize a pointer with a non-zero address in a MISRA-compliant style.<br />
<br />
Thank you for the answer.<br />
<br />
Best regards.]]></description>
			<content:encoded><![CDATA[Hello.<br />
My PC-LINT tool gives me an error of violating of rules 11.1, 11.2, 11.3, 11.4 (cast from unsigned char to pointer ) on the line 2:<br />
<br />
line 1: unsigned char* ptr;<br />
line 2: ptr=(unsigned char*)0x12;<br />
<br />
The idea behind is that I want to initialize a pointer with a non-zero address in a MISRA-compliant style.<br />
<br />
Thank you for the answer.<br />
<br />
Best regards.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Double casting to bypass 11.4?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=676</link>
			<pubDate>Fri, 04 Sep 2009 22:48:55 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=350">exoson</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=676</guid>
			<description><![CDATA[I ran into an issue with a static analysis tool the other day.<br />
 <br />
In my example:<br />
pool_ptr-&gt;list = *((UCHAR **) work_ptr); /*violates MISRA 11.4 */<br />
Both pointers are UCHAR *. The first location in the buffer is being used to hold another pointer. <br />
 <br />
Adding an intermediate cast to void * clears the warning.<br />
pool_ptr -&gt; tx_list = *((UCHAR **) (void *)work_ptr);<br />
 <br />
Regardless that this clears the message, I believe it is still a violation of the intent of MISRA 11.4.  Do you agree?<br />
-----------------------------------------------------------------------<br />
Scott Nowell<br />
Validated Software Corporation]]></description>
			<content:encoded><![CDATA[I ran into an issue with a static analysis tool the other day.<br />
 <br />
In my example:<br />
pool_ptr-&gt;list = *((UCHAR **) work_ptr); /*violates MISRA 11.4 */<br />
Both pointers are UCHAR *. The first location in the buffer is being used to hold another pointer. <br />
 <br />
Adding an intermediate cast to void * clears the warning.<br />
pool_ptr -&gt; tx_list = *((UCHAR **) (void *)work_ptr);<br />
 <br />
Regardless that this clears the message, I believe it is still a violation of the intent of MISRA 11.4.  Do you agree?<br />
-----------------------------------------------------------------------<br />
Scott Nowell<br />
Validated Software Corporation]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Violation of Rule 11.4 or Rule 11.5?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=633</link>
			<pubDate>Fri, 06 Mar 2009 09:36:08 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=611">zaffanella</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=633</guid>
			<description><![CDATA[In Section 6.11 of the MISRA-C:2004 document, after the specification of Rule 11.5, the following example is reported:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/* ... snip ... */<br />
const uint16_t * *&nbsp;&nbsp;ppci;&nbsp;&nbsp;&nbsp;&nbsp; /* pointer to pointer to const */<br />
uint16_t * *&nbsp;&nbsp;ppi;<br />
/* ... snip ... */<br />
ppi = (uint16_t&nbsp;&nbsp;* *)ppci;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Not compliant&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */</code></div></div>In my understanding, this is not really a violation of the required Rule 11.5; rather, it is a violation of the advisory Rule 11.4, since the pointed-to types<br />
(namely, <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>const uint16_t *</code></div></div> and <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>uint16_t *</code></div></div>)<br />
are two different pointer (hence, object) types; in particular, they are <span style="font-weight: bold;" class="mycode_b">unqualified</span> types.<br />
<br />
This is quite the same as saying that<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>struct S { const char* s; };<br />
struct T { char* s; };<br />
struct S* ps;<br />
struct T* pt = (struct T*) ps;</code></div></div>is a violation of 11.4 rather than 11.5.<br />
<br />
Is my interpretation correct?<br />
Or is it the case that Rule 11.5 has to be interpreted <span style="font-style: italic;" class="mycode_i">recursively</span>,<br />
so that in the two examples above we would have violations for <span style="font-weight: bold;" class="mycode_b">both</span> 11.4 and 11.5?<br />
<br />
Thanks,<br />
Enea.]]></description>
			<content:encoded><![CDATA[In Section 6.11 of the MISRA-C:2004 document, after the specification of Rule 11.5, the following example is reported:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/* ... snip ... */<br />
const uint16_t * *&nbsp;&nbsp;ppci;&nbsp;&nbsp;&nbsp;&nbsp; /* pointer to pointer to const */<br />
uint16_t * *&nbsp;&nbsp;ppi;<br />
/* ... snip ... */<br />
ppi = (uint16_t&nbsp;&nbsp;* *)ppci;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Not compliant&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */</code></div></div>In my understanding, this is not really a violation of the required Rule 11.5; rather, it is a violation of the advisory Rule 11.4, since the pointed-to types<br />
(namely, <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>const uint16_t *</code></div></div> and <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>uint16_t *</code></div></div>)<br />
are two different pointer (hence, object) types; in particular, they are <span style="font-weight: bold;" class="mycode_b">unqualified</span> types.<br />
<br />
This is quite the same as saying that<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>struct S { const char* s; };<br />
struct T { char* s; };<br />
struct S* ps;<br />
struct T* pt = (struct T*) ps;</code></div></div>is a violation of 11.4 rather than 11.5.<br />
<br />
Is my interpretation correct?<br />
Or is it the case that Rule 11.5 has to be interpreted <span style="font-style: italic;" class="mycode_i">recursively</span>,<br />
so that in the two examples above we would have violations for <span style="font-weight: bold;" class="mycode_b">both</span> 11.4 and 11.5?<br />
<br />
Thanks,<br />
Enea.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Again on rule 11.2 and Exemplar Suite]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=627</link>
			<pubDate>Sat, 14 Feb 2009 15:57:10 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=606">roberto</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=627</guid>
			<description><![CDATA[I agree that one should not write code like<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>float32_1102 = ( float32_t ) void_ptr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Not Compliant */<br />
&nbsp;&nbsp; float64_1102 = ( float64_t ) void_ptr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Not Compliant */</code></div></div><br />
However, my understanding is that those lines do not violate rule 11.2, even taking into account the clarification given in TC1.<br />
Am I correct?<br />
Thanks,<br />
<br />
    Roberto<br />
<br />
P.S. I read the other thread on the forum, but the question was not answered.  I saw that thread is locked, and I do not know what is the right way to resurrect a discussion.  Please accept my apologies if opening another discussion is not appropriate.]]></description>
			<content:encoded><![CDATA[I agree that one should not write code like<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>float32_1102 = ( float32_t ) void_ptr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Not Compliant */<br />
&nbsp;&nbsp; float64_1102 = ( float64_t ) void_ptr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Not Compliant */</code></div></div><br />
However, my understanding is that those lines do not violate rule 11.2, even taking into account the clarification given in TC1.<br />
Am I correct?<br />
Thanks,<br />
<br />
    Roberto<br />
<br />
P.S. I read the other thread on the forum, but the question was not answered.  I saw that thread is locked, and I do not know what is the right way to resurrect a discussion.  Please accept my apologies if opening another discussion is not appropriate.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 11.1 and NULL defined as ((void*) 0)]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=626</link>
			<pubDate>Sat, 14 Feb 2009 14:02:22 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=606">roberto</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=626</guid>
			<description><![CDATA[Please consider the following test program:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define NULL ((void*) 0)<br />
<br />
struct super_block;<br />
struct inode;<br />
<br />
typedef int (*find_inode_t)(struct inode *, unsigned long, void *);<br />
<br />
<br />
extern struct inode * iget4_locked(struct super_block *, unsigned long,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; find_inode_t, void *);<br />
<br />
static inline struct inode *iget(struct super_block *sb, unsigned long ino)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;struct inode *inode = iget4_locked(sb, ino, NULL, NULL);<br />
&nbsp;&nbsp;&nbsp;&nbsp;return inode;<br />
}</code></div></div> <br />
<br />
My reading of rule 11.1 is that NULL (so defined, which is quite common) cannot be passed that way to iget4_locked().  However, since I see <span style="font-style: italic;" class="mycode_i">zillions</span> of violations of this kind, I am caught by the doubt.<br />
Many thanks,<br />
<br />
     Roberto]]></description>
			<content:encoded><![CDATA[Please consider the following test program:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define NULL ((void*) 0)<br />
<br />
struct super_block;<br />
struct inode;<br />
<br />
typedef int (*find_inode_t)(struct inode *, unsigned long, void *);<br />
<br />
<br />
extern struct inode * iget4_locked(struct super_block *, unsigned long,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; find_inode_t, void *);<br />
<br />
static inline struct inode *iget(struct super_block *sb, unsigned long ino)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;struct inode *inode = iget4_locked(sb, ino, NULL, NULL);<br />
&nbsp;&nbsp;&nbsp;&nbsp;return inode;<br />
}</code></div></div> <br />
<br />
My reading of rule 11.1 is that NULL (so defined, which is quite common) cannot be passed that way to iget4_locked().  However, since I see <span style="font-style: italic;" class="mycode_i">zillions</span> of violations of this kind, I am caught by the doubt.<br />
Many thanks,<br />
<br />
     Roberto]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 11.2 and example from Exemplar Suite]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=438</link>
			<pubDate>Tue, 08 Jan 2008 12:35:36 +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=438</guid>
			<description><![CDATA[In the mc2_1102.c file there is a following example:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>float32_t float32_1102;<br />
&nbsp;&nbsp; void *void_ptr = ( void * ) get_int32_ptr ( );<br />
&nbsp;&nbsp; float32_1102 = ( float32_t ) void_ptr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Not Compliant */</code></div></div><br />
Is the conversion between void pointer and a float type object disallowed by the 11.2 rule?<br />
<br />
According to my understanding the rule 11.2 disallows conversions only if we are converting to or from a pointer to object. <br />
float type is clearly not a pointer to object type.<br />
Pointer to void is not a pointer to object type, because void is not an object (it's an incomplete type).<br />
<br />
Please correct me if my understanding is not correct.]]></description>
			<content:encoded><![CDATA[In the mc2_1102.c file there is a following example:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>float32_t float32_1102;<br />
&nbsp;&nbsp; void *void_ptr = ( void * ) get_int32_ptr ( );<br />
&nbsp;&nbsp; float32_1102 = ( float32_t ) void_ptr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Not Compliant */</code></div></div><br />
Is the conversion between void pointer and a float type object disallowed by the 11.2 rule?<br />
<br />
According to my understanding the rule 11.2 disallows conversions only if we are converting to or from a pointer to object. <br />
float type is clearly not a pointer to object type.<br />
Pointer to void is not a pointer to object type, because void is not an object (it's an incomplete type).<br />
<br />
Please correct me if my understanding is not correct.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[11.4 A cast should not be performed ...]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=407</link>
			<pubDate>Tue, 06 Nov 2007 10:13:45 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=407">Frank Haug</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=407</guid>
			<description><![CDATA[... between a pointer to object type and a different pointer to object type (advisory).<br />
<br />
Additional comment: \" Conversions of this type may be invalid if the new pointer type requires a stricter alignment.\"<br />
<br />
---<br />
<br />
I think there can be further risks. I suppose - e.g. - casting a signed pointer onto an unsigned pointer (of the same bitwidth and alignment) itself is not risky. Dangerous can be to WORK with the casted pointer regarding its content, it is pointing onto. In this case the cast itself would not be dangerous, but the possibilities afterwards are.<br />
<br />
example: <br />
<br />
unsigned int foo (signed int* ps)<br />
{<br />
unsigned int* pu;<br />
<br />
  pu = (unsigned int*) ps; // assumed to be no problem itself<br />
  *pu = ... ;                     // assumed to be no problem itself<br />
                  // but can be a problem later, when the content of the incoming pointer is used afterwards <br />
} <br />
<br />
Can anybody confirm ? I think it can be of interest to know the problems in more precision. Does anybody know other implications (not applying such casts) ?<br />
<br />
Regards,<br />
Frank]]></description>
			<content:encoded><![CDATA[... between a pointer to object type and a different pointer to object type (advisory).<br />
<br />
Additional comment: \" Conversions of this type may be invalid if the new pointer type requires a stricter alignment.\"<br />
<br />
---<br />
<br />
I think there can be further risks. I suppose - e.g. - casting a signed pointer onto an unsigned pointer (of the same bitwidth and alignment) itself is not risky. Dangerous can be to WORK with the casted pointer regarding its content, it is pointing onto. In this case the cast itself would not be dangerous, but the possibilities afterwards are.<br />
<br />
example: <br />
<br />
unsigned int foo (signed int* ps)<br />
{<br />
unsigned int* pu;<br />
<br />
  pu = (unsigned int*) ps; // assumed to be no problem itself<br />
  *pu = ... ;                     // assumed to be no problem itself<br />
                  // but can be a problem later, when the content of the incoming pointer is used afterwards <br />
} <br />
<br />
Can anybody confirm ? I think it can be of interest to know the problems in more precision. Does anybody know other implications (not applying such casts) ?<br />
<br />
Regards,<br />
Frank]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 45 and polymorphism]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=347</link>
			<pubDate>Wed, 07 Mar 2007 15:10:30 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=280">jlb</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=347</guid>
			<description><![CDATA[Hello,<br />
<br />
I am new to MISRA-C rules and in the code I am working on, there this kind of constructs :<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>struct TPL_ACTION {<br />
&nbsp;&nbsp;&nbsp;&nbsp;tpl_action_func action;&nbsp;&nbsp;&nbsp;&nbsp;/**&lt;&nbsp;&nbsp;action function pointer&nbsp;&nbsp; */<br />
};<br />
<br />
typedef struct TPL_ACTION tpl_action;</code></div></div><br />
and for instance :<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>struct TPL_TASK_ACTIVATION_ACTION {<br />
&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;&nbsp;base action&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */<br />
&nbsp;&nbsp;&nbsp;&nbsp;tpl_action&nbsp;&nbsp;&nbsp;&nbsp;b_desc;<br />
&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;&nbsp;task descriptor pointer&nbsp;&nbsp;&nbsp;&nbsp; */<br />
&nbsp;&nbsp;&nbsp;&nbsp;tpl_task&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*task;<br />
};<br />
<br />
typedef struct TPL_TASK_ACTIVATION_ACTION<br />
tpl_task_activation_action ;</code></div></div><br />
tpl_action is an abstract type (no instance) and tpl_task_activation_action is a concrete type.<br />
<br />
The function pointed by <span style="font-style: italic;" class="mycode_i">action</span> function pointer takes a tpl_action * and casts it to the appropriate concrete type.<br />
<br />
I understand rule 45 disallows pointer type casting to avoid memory alignment problems but here the first member of the abstract type is of the same type as the first member of the concrete type.<br />
<br />
Is it legal ?<br />
<br />
Best regards]]></description>
			<content:encoded><![CDATA[Hello,<br />
<br />
I am new to MISRA-C rules and in the code I am working on, there this kind of constructs :<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>struct TPL_ACTION {<br />
&nbsp;&nbsp;&nbsp;&nbsp;tpl_action_func action;&nbsp;&nbsp;&nbsp;&nbsp;/**&lt;&nbsp;&nbsp;action function pointer&nbsp;&nbsp; */<br />
};<br />
<br />
typedef struct TPL_ACTION tpl_action;</code></div></div><br />
and for instance :<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>struct TPL_TASK_ACTIVATION_ACTION {<br />
&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;&nbsp;base action&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */<br />
&nbsp;&nbsp;&nbsp;&nbsp;tpl_action&nbsp;&nbsp;&nbsp;&nbsp;b_desc;<br />
&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;&nbsp;task descriptor pointer&nbsp;&nbsp;&nbsp;&nbsp; */<br />
&nbsp;&nbsp;&nbsp;&nbsp;tpl_task&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*task;<br />
};<br />
<br />
typedef struct TPL_TASK_ACTIVATION_ACTION<br />
tpl_task_activation_action ;</code></div></div><br />
tpl_action is an abstract type (no instance) and tpl_task_activation_action is a concrete type.<br />
<br />
The function pointed by <span style="font-style: italic;" class="mycode_i">action</span> function pointer takes a tpl_action * and casts it to the appropriate concrete type.<br />
<br />
I understand rule 45 disallows pointer type casting to avoid memory alignment problems but here the first member of the abstract type is of the same type as the first member of the concrete type.<br />
<br />
Is it legal ?<br />
<br />
Best regards]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Other question about pointer to void]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=339</link>
			<pubDate>Wed, 07 Feb 2007 20:48:02 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=231">fwamolina</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=339</guid>
			<description><![CDATA[In misraC-2004 when starts section 6.11 - Pointer type Conversion says the following:<br />
<br />
\"Conversions involving pointer types require an explicit cast except when:<br />
The conversion is between a pointer to object an a pointer to void....\"<br />
<br />
my question is if this example is compliance with that.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void func (void)<br />
{<br />
&nbsp;&nbsp;void*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pt_V;<br />
&nbsp;&nbsp;uint8_t*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pt_A;<br />
&nbsp;&nbsp;uint32_t*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pt_B;<br />
<br />
&nbsp;&nbsp;.<br />
&nbsp;&nbsp;.<br />
&nbsp;&nbsp;.<br />
<br />
&nbsp;&nbsp;pt_V = pt_A;<br />
<br />
&nbsp;&nbsp;/* use pointer */<br />
<br />
&nbsp;&nbsp;pt_V = pt_B;<br />
<br />
&nbsp;&nbsp;/* use pointer */<br />
<br />
&nbsp;&nbsp;.<br />
&nbsp;&nbsp;. <br />
&nbsp;&nbsp;.<br />
}</code></div></div><br />
thank you.]]></description>
			<content:encoded><![CDATA[In misraC-2004 when starts section 6.11 - Pointer type Conversion says the following:<br />
<br />
\"Conversions involving pointer types require an explicit cast except when:<br />
The conversion is between a pointer to object an a pointer to void....\"<br />
<br />
my question is if this example is compliance with that.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void func (void)<br />
{<br />
&nbsp;&nbsp;void*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pt_V;<br />
&nbsp;&nbsp;uint8_t*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pt_A;<br />
&nbsp;&nbsp;uint32_t*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pt_B;<br />
<br />
&nbsp;&nbsp;.<br />
&nbsp;&nbsp;.<br />
&nbsp;&nbsp;.<br />
<br />
&nbsp;&nbsp;pt_V = pt_A;<br />
<br />
&nbsp;&nbsp;/* use pointer */<br />
<br />
&nbsp;&nbsp;pt_V = pt_B;<br />
<br />
&nbsp;&nbsp;/* use pointer */<br />
<br />
&nbsp;&nbsp;.<br />
&nbsp;&nbsp;. <br />
&nbsp;&nbsp;.<br />
}</code></div></div><br />
thank you.]]></content:encoded>
		</item>
	</channel>
</rss>