<?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.9 Initialization]]></title>
		<link>https://forum.misra.org.uk/</link>
		<description><![CDATA[MISRA Discussion Forums - https://forum.misra.org.uk]]></description>
		<pubDate>Thu, 05 Nov 2026 20:03:05 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[named vs positional initialization]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1751</link>
			<pubDate>Thu, 04 Sep 2025 11:27:01 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6679">delirium5223</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1751</guid>
			<description><![CDATA[What do you think about advising against using mixed aggregate initialization, named vs positional.<br />
<br />
When mixing them there is a higher chance for human confusion/mistake. e.g. not covering all of them etc<br />
<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef struct<br />
{<br />
  int x;<br />
  int y;<br />
  int z;<br />
} TypeA;<br />
<br />
void test4(void)<br />
{<br />
  TypeA obj = { .y = 2, 3 }; // nok mixed aggregate initialization, named vs positional<br />
  TypeA obj2 = { 3 , .y = 2 }; // nok<br />
  TypeA obj3 = { 3 , 2, 4 }; //ok, not mixed<br />
  TypeA obj4 = { .x = 3 , .z = 4, .y = 2 }; //ok, not mixed<br />
}</code></div></div><br />
Rule 9.6 only prohibits them when they are embedded structs, not for single struct.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/* Non-compliant - chained designators and implicit positional initializers mixed */<br />
struct T tt = {<br />
1,<br />
.s.x = 2, /* To a human reader, this looks like .z is being initialized */<br />
3, /* tt is actually initialized as { 1, { 2, 3 }, 0 } */<br />
}; /* This also violates Rule 9.2 */</code></div></div>]]></description>
			<content:encoded><![CDATA[What do you think about advising against using mixed aggregate initialization, named vs positional.<br />
<br />
When mixing them there is a higher chance for human confusion/mistake. e.g. not covering all of them etc<br />
<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef struct<br />
{<br />
  int x;<br />
  int y;<br />
  int z;<br />
} TypeA;<br />
<br />
void test4(void)<br />
{<br />
  TypeA obj = { .y = 2, 3 }; // nok mixed aggregate initialization, named vs positional<br />
  TypeA obj2 = { 3 , .y = 2 }; // nok<br />
  TypeA obj3 = { 3 , 2, 4 }; //ok, not mixed<br />
  TypeA obj4 = { .x = 3 , .z = 4, .y = 2 }; //ok, not mixed<br />
}</code></div></div><br />
Rule 9.6 only prohibits them when they are embedded structs, not for single struct.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/* Non-compliant - chained designators and implicit positional initializers mixed */<br />
struct T tt = {<br />
1,<br />
.s.x = 2, /* To a human reader, this looks like .z is being initialized */<br />
3, /* tt is actually initialized as { 1, { 2, 3 }, 0 } */<br />
}; /* This also violates Rule 9.2 */</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[MISRA C:2012 9.3 clarification]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1555</link>
			<pubDate>Tue, 24 Nov 2020 09:19:24 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5542">mcks</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1555</guid>
			<description><![CDATA[I try to implement the checks for "9.3 - Arrays shall not be partially initialized" in Cppcheck, and would like to have some clarifications.<br />
<br />
Is it ok to mix initializers like this, as long as every element gets initialized?<br />
<br />
int32_t a[3] = { 1, 2, [2]=3 };<br />
<br />
For multi-dimensional arrays, this would be compliant:<br />
<br />
int32_t b[2][2] = { { 1, 2 }, { [1]=4 } };<br />
<br />
beacuse b[1] is initialized with only a designated initializer.<br />
<br />
<br />
As for c, both the array subobjects c[0] and c[1] are fully initialized, but there is no initialization of c[2]. Does that make the statement non-compliant?<br />
<br />
int32_t c[3][2] = { { 1, 2 }, { 3, 4 } };<br />
<br />
<br />
What about the arrays below, are they compliant or not, and why? Also, are they violatin 9.2 or 9.4?<br />
int32_t d[1][2] = { [0][1]=2, [0]={1} };<br />
int32_t e[1][2] = { [0]={1}, [0][1]=2 };<br />
int32_t f[3][2] = { [1]={3, 4}, { 5, 6 }, [0][1]=2, [0][0]=1 };<br />
int32_t g[2][2] = { { 1, 2 }, [1][0]=3, 4 };<br />
<br />
Let me know what you think. If you have more (tricky) examples, then please share!]]></description>
			<content:encoded><![CDATA[I try to implement the checks for "9.3 - Arrays shall not be partially initialized" in Cppcheck, and would like to have some clarifications.<br />
<br />
Is it ok to mix initializers like this, as long as every element gets initialized?<br />
<br />
int32_t a[3] = { 1, 2, [2]=3 };<br />
<br />
For multi-dimensional arrays, this would be compliant:<br />
<br />
int32_t b[2][2] = { { 1, 2 }, { [1]=4 } };<br />
<br />
beacuse b[1] is initialized with only a designated initializer.<br />
<br />
<br />
As for c, both the array subobjects c[0] and c[1] are fully initialized, but there is no initialization of c[2]. Does that make the statement non-compliant?<br />
<br />
int32_t c[3][2] = { { 1, 2 }, { 3, 4 } };<br />
<br />
<br />
What about the arrays below, are they compliant or not, and why? Also, are they violatin 9.2 or 9.4?<br />
int32_t d[1][2] = { [0][1]=2, [0]={1} };<br />
int32_t e[1][2] = { [0]={1}, [0][1]=2 };<br />
int32_t f[3][2] = { [1]={3, 4}, { 5, 6 }, [0][1]=2, [0][0]=1 };<br />
int32_t g[2][2] = { { 1, 2 }, [1][0]=3, 4 };<br />
<br />
Let me know what you think. If you have more (tricky) examples, then please share!]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Initialisation of arrays of floats]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1357</link>
			<pubDate>Wed, 19 Jul 2017 13:04:46 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4792">sdcandy</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1357</guid>
			<description><![CDATA[Rule 9.3 in MISRA C:2012 has an exception which states "An initializer of the form { 0 } may be used to explicitly initialize all elements of an array object or subobject".  This means that something of the form is acceptable:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>uint32_t x[3] = { 0 };</code></div></div><br />
When using floating point types is it also acceptable to use something of the form:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef double float64_t;<br />
float64_t array_a[10] = { 0.0 };</code></div></div><br />
-Andy.]]></description>
			<content:encoded><![CDATA[Rule 9.3 in MISRA C:2012 has an exception which states "An initializer of the form { 0 } may be used to explicitly initialize all elements of an array object or subobject".  This means that something of the form is acceptable:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>uint32_t x[3] = { 0 };</code></div></div><br />
When using floating point types is it also acceptable to use something of the form:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>typedef double float64_t;<br />
float64_t array_a[10] = { 0.0 };</code></div></div><br />
-Andy.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Note 9003: could define variable at block scope]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1285</link>
			<pubDate>Wed, 12 Oct 2016 08:39:58 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4165">PeterW</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1285</guid>
			<description><![CDATA[Hi,<br />
In my code I have a static const array which is declared outside the block scope of the function where itâ€™s used. Also it is only used by one function, so the Note 9003 is correct. <br />
But the array is large and will ruin the overview of the function. So I want to suppress the warning using /*lint -e9003*/ before the array and /*lint +e9003*/ behind it.<br />
But this has no effect. As I suppress the warning global it works, but this shall not be the way to do. <br />
Any idea how to suppress the warning local for just one variable?]]></description>
			<content:encoded><![CDATA[Hi,<br />
In my code I have a static const array which is declared outside the block scope of the function where itâ€™s used. Also it is only used by one function, so the Note 9003 is correct. <br />
But the array is large and will ruin the overview of the function. So I want to suppress the warning using /*lint -e9003*/ before the array and /*lint +e9003*/ behind it.<br />
But this has no effect. As I suppress the warning global it works, but this shall not be the way to do. <br />
Any idea how to suppress the warning local for just one variable?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[9.3 and {0}]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=982</link>
			<pubDate>Wed, 11 Sep 2013 19:58:02 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=64">gs</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=982</guid>
			<description><![CDATA[Would the following example be compliant with rule #9.3?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>int a[3][2] = {0};</code></div></div>]]></description>
			<content:encoded><![CDATA[Would the following example be compliant with rule #9.3?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>int a[3][2] = {0};</code></div></div>]]></content:encoded>
		</item>
	</channel>
</rss>