<?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.17 Pointers and Arrays]]></title>
		<link>https://forum.misra.org.uk/</link>
		<description><![CDATA[MISRA Discussion Forums - https://forum.misra.org.uk]]></description>
		<pubDate>Thu, 05 Nov 2026 19:06:13 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[MISRA2004 Rule 17.4 How to solve the Rule violation]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1472</link>
			<pubDate>Tue, 19 Feb 2019 04:17:03 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5211">Tejas Kore</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1472</guid>
			<description><![CDATA[I have an issue regarding the rule violation in which I'm using a <span style="font-weight: bold;" class="mycode_b">2D array inside a structure</span> and apparently The Rule 17.4 says <span style="font-weight: bold;" class="mycode_b">it isn't compliant</span>. Is Declaring arryas inside a structure/union not compliant and why is it so? <span style="text-decoration: underline;" class="mycode_u">What exactly is the alternative for it?</span><br />
Help would be appreciated ASAP. Following is the example code. Thanks in advance.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#include <br />
void func1(unsigned char abc);<br />
<br />
typedef struct teststructure<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;float buf[5][3];<br />
}teststruct;<br />
<br />
int main()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;unsigned char abc;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;func1(abc);<br />
<br />
}<br />
<br />
void func1(unsigned char abc)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;teststruct TEST;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;float fData = 54.0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;TEST.buf[2][1] = fData;<br />
}</code></div></div>]]></description>
			<content:encoded><![CDATA[I have an issue regarding the rule violation in which I'm using a <span style="font-weight: bold;" class="mycode_b">2D array inside a structure</span> and apparently The Rule 17.4 says <span style="font-weight: bold;" class="mycode_b">it isn't compliant</span>. Is Declaring arryas inside a structure/union not compliant and why is it so? <span style="text-decoration: underline;" class="mycode_u">What exactly is the alternative for it?</span><br />
Help would be appreciated ASAP. Following is the example code. Thanks in advance.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#include <br />
void func1(unsigned char abc);<br />
<br />
typedef struct teststructure<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;float buf[5][3];<br />
}teststruct;<br />
<br />
int main()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;unsigned char abc;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;func1(abc);<br />
<br />
}<br />
<br />
void func1(unsigned char abc)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;teststruct TEST;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;float fData = 54.0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;TEST.buf[2][1] = fData;<br />
}</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[About 17.4 Question?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1242</link>
			<pubDate>Thu, 05 May 2016 09:36:39 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4351">hutry999</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1242</guid>
			<description><![CDATA[I need read some parameters from EEPROM. My Code as below:<br />
<br />
typedef struct<br />
{<br />
	Uint16  ErrorCode;          <br />
	Uint16	ErrDCVoltage;	<br />
	Uint16  ErrMCUState;	<br />
	Uint8 	ErrMotorModeCmd;<br />
	Uint8 	ErrDriveState; 	<br />
	Uint16	ErrTorqueCmd;   <br />
	Uint16	ErrTorqueFed;   <br />
	Uint16	ErrSpeedSet;	<br />
	Uint16	ErrSpeed;       <br />
	Uint8 	ErrIGBTTemp;    <br />
	Uint8 	ErrMotorTemp;   <br />
	Uint16	ErrUd; 			<br />
	Uint16	ErrUq;			<br />
	Uint16	ErrIdRef;       <br />
	Uint16	ErrIqRef;       <br />
	Uint16	ErrIdFed;       <br />
	Uint16	ErrIqFed;       <br />
	Uint16	ErrState;		<br />
	Uint8 	Err12V;  		<br />
	Uint8   Angle;			<br />
	Uint8   AngleInit;		<br />
	Uint8	ErrMCUTemp;<br />
	Uint16  DC_Cur;<br />
}ErrorLog_t;<br />
<br />
void LoadError(ErrorLog_t* Err,Uint16 Index)  <br />
 {<br />
    Uint16 i;<br />
	Uint16 *PrErrLog;<br />
	PrErrLog = (uint16 *)Err;<br />
	for(i=0u;iErrorCode =     ReadEeprom(0u);     <br />
Err-&gt;ErrDCVoltage =     ReadEeprom(1u);     	<br />
Err-&gt;ErrMCUState =     ReadEeprom(2u);     <br />
....<br />
	<br />
if my struct has more than 100 items, What can I do?]]></description>
			<content:encoded><![CDATA[I need read some parameters from EEPROM. My Code as below:<br />
<br />
typedef struct<br />
{<br />
	Uint16  ErrorCode;          <br />
	Uint16	ErrDCVoltage;	<br />
	Uint16  ErrMCUState;	<br />
	Uint8 	ErrMotorModeCmd;<br />
	Uint8 	ErrDriveState; 	<br />
	Uint16	ErrTorqueCmd;   <br />
	Uint16	ErrTorqueFed;   <br />
	Uint16	ErrSpeedSet;	<br />
	Uint16	ErrSpeed;       <br />
	Uint8 	ErrIGBTTemp;    <br />
	Uint8 	ErrMotorTemp;   <br />
	Uint16	ErrUd; 			<br />
	Uint16	ErrUq;			<br />
	Uint16	ErrIdRef;       <br />
	Uint16	ErrIqRef;       <br />
	Uint16	ErrIdFed;       <br />
	Uint16	ErrIqFed;       <br />
	Uint16	ErrState;		<br />
	Uint8 	Err12V;  		<br />
	Uint8   Angle;			<br />
	Uint8   AngleInit;		<br />
	Uint8	ErrMCUTemp;<br />
	Uint16  DC_Cur;<br />
}ErrorLog_t;<br />
<br />
void LoadError(ErrorLog_t* Err,Uint16 Index)  <br />
 {<br />
    Uint16 i;<br />
	Uint16 *PrErrLog;<br />
	PrErrLog = (uint16 *)Err;<br />
	for(i=0u;iErrorCode =     ReadEeprom(0u);     <br />
Err-&gt;ErrDCVoltage =     ReadEeprom(1u);     	<br />
Err-&gt;ErrMCUState =     ReadEeprom(2u);     <br />
....<br />
	<br />
if my struct has more than 100 items, What can I do?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 17.4 - can I reference to an array, inside a struct?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=976</link>
			<pubDate>Fri, 23 Aug 2013 17:38:53 +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=976</guid>
			<description><![CDATA[I want to define a list of actions in ROM, so it cannot get corrupted. An array of struct, in ROM, where each struct contains enough information to define what the MCU should do.<br />
<br />
One of the actions is to read some info from an exernal device. So it needs to go into a buffer, and the buffer is obviously in RAM.<br />
<br />
The problem I have is, how do I make a typedef for a struct, where one member of the struct is a reference to the buffer? I will need to use the buffer as an array, and referring to an array element by index is of course not allowed, if a pointer type is used for the array.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef s_SomeStruct<br />
{<br />
&nbsp;&nbsp;uint8_t *buf;&nbsp;&nbsp;/* not ok, because SomeStruct.buf[x] will not be compliant */<br />
&nbsp;&nbsp;size_t bufsize;<br />
} TSomeStruct;</code></div></div>But I cannot find a way to use an array type. For function parameters, I could have foo(uint8_t buf[]) but it's not going to compile in a structure definition<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef s_SomeStruct<br />
{<br />
&nbsp;&nbsp;uint8_t buf[]; /* you wha'? */<br />
&nbsp;&nbsp;size_t bufsize;<br />
} TSomeStruct;</code></div></div>Is there a known way around this, other than creating a deviation? <br />
<br />
Thanks<br />
<br />
Frank]]></description>
			<content:encoded><![CDATA[I want to define a list of actions in ROM, so it cannot get corrupted. An array of struct, in ROM, where each struct contains enough information to define what the MCU should do.<br />
<br />
One of the actions is to read some info from an exernal device. So it needs to go into a buffer, and the buffer is obviously in RAM.<br />
<br />
The problem I have is, how do I make a typedef for a struct, where one member of the struct is a reference to the buffer? I will need to use the buffer as an array, and referring to an array element by index is of course not allowed, if a pointer type is used for the array.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef s_SomeStruct<br />
{<br />
&nbsp;&nbsp;uint8_t *buf;&nbsp;&nbsp;/* not ok, because SomeStruct.buf[x] will not be compliant */<br />
&nbsp;&nbsp;size_t bufsize;<br />
} TSomeStruct;</code></div></div>But I cannot find a way to use an array type. For function parameters, I could have foo(uint8_t buf[]) but it's not going to compile in a structure definition<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef s_SomeStruct<br />
{<br />
&nbsp;&nbsp;uint8_t buf[]; /* you wha'? */<br />
&nbsp;&nbsp;size_t bufsize;<br />
} TSomeStruct;</code></div></div>Is there a known way around this, other than creating a deviation? <br />
<br />
Thanks<br />
<br />
Frank]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 17.4 - array elements contained inside structure def]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=935</link>
			<pubDate>Mon, 21 Jan 2013 08:08:31 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=2410">sshidore</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=935</guid>
			<description><![CDATA[â€¢	MISRA C rule 17.4 says arithmetic operations shall not be performed on pointers, as they may result into referencing to non-existing addresses.<br />
â€¢	Alternative to this is to catch a pointer being received as an argument into the respective type of an array, for e.g. catch â€˜&amp;arrâ€™ into â€˜arr[]â€™, and use array indexing to access its elements. This works well for pointers of basic data types.<br />
â€¢	Problem arises in the case of accessing array elements contained by a structure.<br />
â€¢	e.g.      <br />
        struct message<br />
        {<br />
              int address;<br />
              int length;<br />
              int data[50];<br />
        }m1,m2;<br />
<br />
â€¢	Now, the statement â€œsource_node = m1.data[SOURCE_NODE_INDEX]â€ triggers this 17.4 non-compliance note.<br />
â€¢	This happens when accessing only the array elements, and not for single variables of a structure definition.<br />
â€¢	So the question I have is, what is the best way to access individual array elements contained inside a structure definition?]]></description>
			<content:encoded><![CDATA[â€¢	MISRA C rule 17.4 says arithmetic operations shall not be performed on pointers, as they may result into referencing to non-existing addresses.<br />
â€¢	Alternative to this is to catch a pointer being received as an argument into the respective type of an array, for e.g. catch â€˜&amp;arrâ€™ into â€˜arr[]â€™, and use array indexing to access its elements. This works well for pointers of basic data types.<br />
â€¢	Problem arises in the case of accessing array elements contained by a structure.<br />
â€¢	e.g.      <br />
        struct message<br />
        {<br />
              int address;<br />
              int length;<br />
              int data[50];<br />
        }m1,m2;<br />
<br />
â€¢	Now, the statement â€œsource_node = m1.data[SOURCE_NODE_INDEX]â€ triggers this 17.4 non-compliance note.<br />
â€¢	This happens when accessing only the array elements, and not for single variables of a structure definition.<br />
â€¢	So the question I have is, what is the best way to access individual array elements contained inside a structure definition?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[MISRA rule 17.4 violation ?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=876</link>
			<pubDate>Thu, 26 Jan 2012 08:14:51 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=1742">misterb</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=876</guid>
			<description><![CDATA[Hello,<br />
<br />
my compiler find in the following code a MISRA violation 17.4 at the last view code lines. Is this correct? If yes, please tell me how to solve the above mentioned code. In my opinion there is no MISRA rule 17.4 violation.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define BUF_LEN1&nbsp;&nbsp;&nbsp;&nbsp; (512u)<br />
<br />
/* this violates rule 8.7, but this is intentionaly. It is only a rule 17.4 example */<br />
static uint32_t buf1[BUF_LEN1];<br />
&nbsp;&nbsp;<br />
static struct TestStruct<br />
{<br />
&nbsp;&nbsp;uint32_t *buf;<br />
&nbsp;&nbsp;uint32_t len;<br />
} data1 = {NULL, 0u};<br />
<br />
static void InitStruct(uint32_t _len, uint32_t _buf[]);<br />
static void UseStruct(struct TestStruct * data);<br />
<br />
int32_t main( void )<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;InitStruct(BUF_LEN1, buf1);<br />
&nbsp;&nbsp;&nbsp;&nbsp;UseStruct(&amp;data1);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;return 0;<br />
}<br />
<br />
static void InitStruct(uint32_t _len, uint32_t _buf[])<br />
{<br />
&nbsp;&nbsp;data1.len = _len;<br />
&nbsp;&nbsp;data1.buf = _buf;<br />
}<br />
<br />
static void UseStruct(struct TestStruct * data)<br />
{<br />
&nbsp;&nbsp;uint32_t i;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;for (i=0u; ilen; i++)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* process data in any way ... */<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* this code line causes a MISRA 17.4 violation error by the compiler */<br />
&nbsp;&nbsp;&nbsp;&nbsp;data-&gt;buf[i] = 1u;<br />
&nbsp;&nbsp;}<br />
}</code></div></div><br />
Many thanks in advance and best regards,<br />
<br />
Michael]]></description>
			<content:encoded><![CDATA[Hello,<br />
<br />
my compiler find in the following code a MISRA violation 17.4 at the last view code lines. Is this correct? If yes, please tell me how to solve the above mentioned code. In my opinion there is no MISRA rule 17.4 violation.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define BUF_LEN1&nbsp;&nbsp;&nbsp;&nbsp; (512u)<br />
<br />
/* this violates rule 8.7, but this is intentionaly. It is only a rule 17.4 example */<br />
static uint32_t buf1[BUF_LEN1];<br />
&nbsp;&nbsp;<br />
static struct TestStruct<br />
{<br />
&nbsp;&nbsp;uint32_t *buf;<br />
&nbsp;&nbsp;uint32_t len;<br />
} data1 = {NULL, 0u};<br />
<br />
static void InitStruct(uint32_t _len, uint32_t _buf[]);<br />
static void UseStruct(struct TestStruct * data);<br />
<br />
int32_t main( void )<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;InitStruct(BUF_LEN1, buf1);<br />
&nbsp;&nbsp;&nbsp;&nbsp;UseStruct(&amp;data1);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;return 0;<br />
}<br />
<br />
static void InitStruct(uint32_t _len, uint32_t _buf[])<br />
{<br />
&nbsp;&nbsp;data1.len = _len;<br />
&nbsp;&nbsp;data1.buf = _buf;<br />
}<br />
<br />
static void UseStruct(struct TestStruct * data)<br />
{<br />
&nbsp;&nbsp;uint32_t i;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;for (i=0u; ilen; i++)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* process data in any way ... */<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* this code line causes a MISRA 17.4 violation error by the compiler */<br />
&nbsp;&nbsp;&nbsp;&nbsp;data-&gt;buf[i] = 1u;<br />
&nbsp;&nbsp;}<br />
}</code></div></div><br />
Many thanks in advance and best regards,<br />
<br />
Michael]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 17.1 compatibility]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=856</link>
			<pubDate>Wed, 05 Oct 2011 07:54:26 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=1742">misterb</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=856</guid>
			<description><![CDATA[Dear all,<br />
<br />
below, you find code that shall be full MISRA-C:2004 compatible except MISRA rule 17.1 (according to my compiler). I removed the header file module.h for readability.<br />
<br />
[code]<br />
/* now module.c begins */<br />
float32_t Defaults[6];<br />
<br />
void misra17_1test(const float32_t in[6])<br />
{<br />
  uint32_t s = 0u;<br />
  float32_t mythreshold = 0.0f;<br />
  float32_t tmpMax = 0.0f;<br />
  for (s = 0u; s &lt; 6u; s++) {<br />
       mythreshold = in[s]; /* a MISRA 17.1 violation is detected here by compiler */ <br />
<br />
    /* do something */ <br />
       <br />
    if (tmpMax &gt; mythreshold) {<br />
      /* do something */<br />
    }<br />
    else {<br />
      /* do something */<br />
    }<br />
  }<br />
}<br />
*-----------------------------------------------------------------------------------------*/<br />
/* now the main.c module begins */<br />
extern float32_t Defaults[6];<br />
<br />
int32_t main(void)<br />
{<br />
  int32_t j = 0;<br />
	for(j=0; j]]></description>
			<content:encoded><![CDATA[Dear all,<br />
<br />
below, you find code that shall be full MISRA-C:2004 compatible except MISRA rule 17.1 (according to my compiler). I removed the header file module.h for readability.<br />
<br />
[code]<br />
/* now module.c begins */<br />
float32_t Defaults[6];<br />
<br />
void misra17_1test(const float32_t in[6])<br />
{<br />
  uint32_t s = 0u;<br />
  float32_t mythreshold = 0.0f;<br />
  float32_t tmpMax = 0.0f;<br />
  for (s = 0u; s &lt; 6u; s++) {<br />
       mythreshold = in[s]; /* a MISRA 17.1 violation is detected here by compiler */ <br />
<br />
    /* do something */ <br />
       <br />
    if (tmpMax &gt; mythreshold) {<br />
      /* do something */<br />
    }<br />
    else {<br />
      /* do something */<br />
    }<br />
  }<br />
}<br />
*-----------------------------------------------------------------------------------------*/<br />
/* now the main.c module begins */<br />
extern float32_t Defaults[6];<br />
<br />
int32_t main(void)<br />
{<br />
  int32_t j = 0;<br />
	for(j=0; j]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Would strlen() be possible with Rule 17.4?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=855</link>
			<pubDate>Thu, 29 Sep 2011 21:59:06 +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=855</guid>
			<description><![CDATA[Small function I am trying to write is to take a string literal, and copy [part of] it to an array.<br />
<br />
The array is fine, declared as an array and only accessed using indexing. But I cannot figure out how to search the string for particular sequences of char.<br />
<br />
It's a string literal, so passed into the function as<br />
  foo("Hello World");<br />
So the parameter is const char_t *. So how could I do anything with that, even find the length of it? I can't step the pointer through it, I can't even access it by index. Is such a thing as a string literal even legal? <br />
<br />
void foo(const Octet *p)<br />
{<br />
  /* ...Now what? p[n] is not legal because Octet * is not an array type,<br />
     and p++ would be a definite no-no.<br />
  */<br />
}<br />
<br />
If I declared it as <br />
  void foo(const char_t c[])<br />
would that be legitimate? It's legal C, I think, and it looks like an array declaration, but I don't see the difference between that and the previous. I can call it with<br />
char_t *p;<br />
  ...<br />
  foo(p);<br />
or even<br />
  foo(NULL);<br />
without a compiler warning (using gcc -ansi -pedantic -Wall; I'm sure PC-Lint would notice, but I don't have it here at home). So if the previous declaration was illegal, would this be also?<br />
<br />
If I understand correctly, then it seems to me that even a simple function like strlen() could not be written, in a way that would be compliant. Is that, in fact, the case?<br />
<br />
Frank]]></description>
			<content:encoded><![CDATA[Small function I am trying to write is to take a string literal, and copy [part of] it to an array.<br />
<br />
The array is fine, declared as an array and only accessed using indexing. But I cannot figure out how to search the string for particular sequences of char.<br />
<br />
It's a string literal, so passed into the function as<br />
  foo("Hello World");<br />
So the parameter is const char_t *. So how could I do anything with that, even find the length of it? I can't step the pointer through it, I can't even access it by index. Is such a thing as a string literal even legal? <br />
<br />
void foo(const Octet *p)<br />
{<br />
  /* ...Now what? p[n] is not legal because Octet * is not an array type,<br />
     and p++ would be a definite no-no.<br />
  */<br />
}<br />
<br />
If I declared it as <br />
  void foo(const char_t c[])<br />
would that be legitimate? It's legal C, I think, and it looks like an array declaration, but I don't see the difference between that and the previous. I can call it with<br />
char_t *p;<br />
  ...<br />
  foo(p);<br />
or even<br />
  foo(NULL);<br />
without a compiler warning (using gcc -ansi -pedantic -Wall; I'm sure PC-Lint would notice, but I don't have it here at home). So if the previous declaration was illegal, would this be also?<br />
<br />
If I understand correctly, then it seems to me that even a simple function like strlen() could not be written, in a way that would be compliant. Is that, in fact, the case?<br />
<br />
Frank]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Function returning pointer to array - Rule 17.4]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=746</link>
			<pubDate>Thu, 24 Jun 2010 13:24:11 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=1097">Greg Middleton</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=746</guid>
			<description><![CDATA[I have a function returning a pointer to an array, not an uncommon situation I would think.<br />
How can I reference elements in that array without violating Rule 17.4 ?.<br />
1. Indexing is not compliant as the return type is not an array.<br />
2. Pointer arithmetic is not compliant.<br />
So it looks like returning pointers to arrays is effectively banned by this rule, is that the case?.]]></description>
			<content:encoded><![CDATA[I have a function returning a pointer to an array, not an uncommon situation I would think.<br />
How can I reference elements in that array without violating Rule 17.4 ?.<br />
1. Indexing is not compliant as the return type is not an array.<br />
2. Pointer arithmetic is not compliant.<br />
So it looks like returning pointers to arrays is effectively banned by this rule, is that the case?.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 17.4]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=727</link>
			<pubDate>Wed, 31 Mar 2010 07:25:11 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=955">mshearer123</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=727</guid>
			<description><![CDATA[Hi,<br />
I am finding a violation (with IBM logiscope) when i use an array within a structure.<br />
<br />
so my structure is:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef struct<br />
{<br />
unsigned char a;<br />
unsigned char b;<br />
unsigned char c[10];<br />
unsigned char d;<br />
}mID;</code></div></div>and my main:<br />
<br />
mID tester;<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>int main(void)<br />
{<br />
tester.a = 0x01;<br />
tester.c[2] = 0x02;<br />
tester.c[3] = 0x06;<br />
tester.c[4] = 0x05;<br />
return 0;<br />
}</code></div></div><br />
for each assignment to .c i am told "pointer arithmetic only with array indexing"<br />
<br />
thanks for any advice<br />
<br />
matt]]></description>
			<content:encoded><![CDATA[Hi,<br />
I am finding a violation (with IBM logiscope) when i use an array within a structure.<br />
<br />
so my structure is:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef struct<br />
{<br />
unsigned char a;<br />
unsigned char b;<br />
unsigned char c[10];<br />
unsigned char d;<br />
}mID;</code></div></div>and my main:<br />
<br />
mID tester;<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>int main(void)<br />
{<br />
tester.a = 0x01;<br />
tester.c[2] = 0x02;<br />
tester.c[3] = 0x06;<br />
tester.c[4] = 0x05;<br />
return 0;<br />
}</code></div></div><br />
for each assignment to .c i am told "pointer arithmetic only with array indexing"<br />
<br />
thanks for any advice<br />
<br />
matt]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Clarification of Rule 17.4]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=358</link>
			<pubDate>Tue, 24 Apr 2007 12:14:33 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=285">Graham Andrews</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=358</guid>
			<description><![CDATA[According to the description of the rule 17.4:<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>Array indexing shall only be applied to objects defined as an array type.</blockquote>
.<br />
Given this I do not understand why the following is allowed:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>uint8_t a[10];<br />
uint8_t *p;<br />
<br />
p = a;<br />
p[5] = 0; /* why is this compliant? */</code></div></div>]]></description>
			<content:encoded><![CDATA[According to the description of the rule 17.4:<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>Array indexing shall only be applied to objects defined as an array type.</blockquote>
.<br />
Given this I do not understand why the following is allowed:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>uint8_t a[10];<br />
uint8_t *p;<br />
<br />
p = a;<br />
p[5] = 0; /* why is this compliant? */</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Arithmetic on Pointers are MISRA compliant ?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=74</link>
			<pubDate>Mon, 31 Oct 2005 16:35:46 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=187">lv</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=74</guid>
			<description><![CDATA[The rules 17.1 to 17.3 give some possibilities to manipulate pointers (arithmetic, substraction, comparison) whereas the rule 17.4 doesn't authorize pointer manipulation in any way other than array indexing.<br />
<br />
Should it be possible to explain me where I make a mistake in my understanding?<br />
<br />
In particular, I would like to know if the following code is MISRA 2004 compliant concerning pointer manipulation:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>&nbsp;&nbsp;&nbsp;&nbsp;unsigned int tab[10];<br />
&nbsp;&nbsp;&nbsp;&nbsp;void test(void)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unsigned int *ptr;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ptr = &amp;tab[2];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*ptr = 33;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ptr++;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*&nbsp;&nbsp;MISRA Compliant ? */<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*ptr = 11;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</code></div></div><br />
I thank you in advance.<br />
<br />
Best regards.]]></description>
			<content:encoded><![CDATA[The rules 17.1 to 17.3 give some possibilities to manipulate pointers (arithmetic, substraction, comparison) whereas the rule 17.4 doesn't authorize pointer manipulation in any way other than array indexing.<br />
<br />
Should it be possible to explain me where I make a mistake in my understanding?<br />
<br />
In particular, I would like to know if the following code is MISRA 2004 compliant concerning pointer manipulation:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>&nbsp;&nbsp;&nbsp;&nbsp;unsigned int tab[10];<br />
&nbsp;&nbsp;&nbsp;&nbsp;void test(void)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unsigned int *ptr;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ptr = &amp;tab[2];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*ptr = 33;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ptr++;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*&nbsp;&nbsp;MISRA Compliant ? */<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*ptr = 11;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</code></div></div><br />
I thank you in advance.<br />
<br />
Best regards.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Dynamic memory allocation using malloc()/calloc()]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=15</link>
			<pubDate>Mon, 22 Nov 2004 09:21:10 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=65">raveendran</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=15</guid>
			<description><![CDATA[Hi, <br />
<br />
        I have a few queries with respect to \"dynamic memory allocation\". As per the rule we are not supposed to use functions like \"malloc()\", \"free()\", \"calloc()\" etc. But malloc() is a very common requirement. Most of the embedded system applications use their own application level memory managers so as to make the allocation and de-allocation fast. Do you have any suggestions to get around this problem ( if we can't use malloc, any other way )? <br />
<br />
        One possible solution I can think of right now it to do a static allocation of a big chunk of memory and redirecting all the dynamic memory requirements to that chunk ( basically a kind of memory manager ). But here also we are stuck with one problem. If we write an application level memory manager, it has to cater to all data types. This will require conversion from any data type to \"void*\" and from \"void*\" to any data type ( say \"char*\" ). But Rule No: 45 of MISRA C ( Typecasting from any type to or from pointers shall not be used ) prohibits me doing that also. <br />
<br />
        The third problem is with writing portable code. Its quite common to use codes like (X*)0-&gt;data1 to get the offset to data1 , where X is a structure ( struct X { }; ) and  data1 is a member within that structure. Are we not supposed to use these types of casts too [  (X*)0 ] ??? <br />
<br />
        It would be great if someone could give some possible solutions to these kind of issues. <br />
<br />
        - Thanks <br />
        - Raveendran V.]]></description>
			<content:encoded><![CDATA[Hi, <br />
<br />
        I have a few queries with respect to \"dynamic memory allocation\". As per the rule we are not supposed to use functions like \"malloc()\", \"free()\", \"calloc()\" etc. But malloc() is a very common requirement. Most of the embedded system applications use their own application level memory managers so as to make the allocation and de-allocation fast. Do you have any suggestions to get around this problem ( if we can't use malloc, any other way )? <br />
<br />
        One possible solution I can think of right now it to do a static allocation of a big chunk of memory and redirecting all the dynamic memory requirements to that chunk ( basically a kind of memory manager ). But here also we are stuck with one problem. If we write an application level memory manager, it has to cater to all data types. This will require conversion from any data type to \"void*\" and from \"void*\" to any data type ( say \"char*\" ). But Rule No: 45 of MISRA C ( Typecasting from any type to or from pointers shall not be used ) prohibits me doing that also. <br />
<br />
        The third problem is with writing portable code. Its quite common to use codes like (X*)0-&gt;data1 to get the offset to data1 , where X is a structure ( struct X { }; ) and  data1 is a member within that structure. Are we not supposed to use these types of casts too [  (X*)0 ] ??? <br />
<br />
        It would be great if someone could give some possible solutions to these kind of issues. <br />
<br />
        - Thanks <br />
        - Raveendran V.]]></content:encoded>
		</item>
	</channel>
</rss>