<?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.3 Basic concepts (C++)]]></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:03:35 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[Rule 3-4-1 and lifetimes, initialization, and side effects]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1726</link>
			<pubDate>Wed, 12 Feb 2025 19:06:41 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6392">aromauld</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1726</guid>
			<description><![CDATA[We have some interesting cases for Rule 3-4-1 which we aren't sure whether they are violations or not. Strictly adhering to the rule of reduced visibility could cause issues regarding lifetimes, initialization, and side effects of a constructor/destructor.<br />
<br />
For instance, in the following example, is the intent to require changes to the code so that 'old_value' is not visible after the if body, or is `old_value` considered non-violating?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void fn(int a) {<br />
    int old_value = a;<br />
    a += 4;<br />
    if (a &gt; 10) {<br />
        a = old_value;<br />
    }<br />
&nbsp;&nbsp;&nbsp;&nbsp;// ...<br />
}</code></div></div><br />
Similarly, in cases where an object's constructor or destructor contains side effects, such as with a mutex, is the current visibility of 'merge_thread_lock' intended to be a violation?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void fn(int a) {<br />
    std::unique_lock&lt;std::shared_mutex&gt; merge_thread_lock(global_mutex);<br />
    if (global) {<br />
      global = a;<br />
      merge_thread_lock.unlock();<br />
    }<br />
&nbsp;&nbsp;&nbsp;&nbsp;// ...<br />
}</code></div></div>]]></description>
			<content:encoded><![CDATA[We have some interesting cases for Rule 3-4-1 which we aren't sure whether they are violations or not. Strictly adhering to the rule of reduced visibility could cause issues regarding lifetimes, initialization, and side effects of a constructor/destructor.<br />
<br />
For instance, in the following example, is the intent to require changes to the code so that 'old_value' is not visible after the if body, or is `old_value` considered non-violating?<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void fn(int a) {<br />
    int old_value = a;<br />
    a += 4;<br />
    if (a &gt; 10) {<br />
        a = old_value;<br />
    }<br />
&nbsp;&nbsp;&nbsp;&nbsp;// ...<br />
}</code></div></div><br />
Similarly, in cases where an object's constructor or destructor contains side effects, such as with a mutex, is the current visibility of 'merge_thread_lock' intended to be a violation?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void fn(int a) {<br />
    std::unique_lock&lt;std::shared_mutex&gt; merge_thread_lock(global_mutex);<br />
    if (global) {<br />
      global = a;<br />
      merge_thread_lock.unlock();<br />
    }<br />
&nbsp;&nbsp;&nbsp;&nbsp;// ...<br />
}</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[3-2-4 and pure virtual functions]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1614</link>
			<pubDate>Sun, 10 Apr 2022 06:19:11 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5872">Tobias Loose</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1614</guid>
			<description><![CDATA[Hi!<br />
<br />
Rule 3-2-4 states:<br />
<br />
<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>An identifier with external linkage shall have exactly one definition.</blockquote>
<br />
<br />
This would also apply to pure virtual functions of abstract base classes. I have personally never seen anyone use that feature and gather from reading up about it that it is questionable design to supply definitions for those. In most cases, these functions would be empty and collide with rules about unused code anyway.<br />
<br />
Was this intended or an oversight? I propose to add an exception for pure virtual functions.<br />
<br />
Also, I propose to replace "An" with "All". Otherwise, it would be enough to add one variable somewhere and provide a definition for it.<br />
<br />
Thanks!]]></description>
			<content:encoded><![CDATA[Hi!<br />
<br />
Rule 3-2-4 states:<br />
<br />
<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>An identifier with external linkage shall have exactly one definition.</blockquote>
<br />
<br />
This would also apply to pure virtual functions of abstract base classes. I have personally never seen anyone use that feature and gather from reading up about it that it is questionable design to supply definitions for those. In most cases, these functions would be empty and collide with rules about unused code anyway.<br />
<br />
Was this intended or an oversight? I propose to add an exception for pure virtual functions.<br />
<br />
Also, I propose to replace "An" with "All". Otherwise, it would be enough to add one variable somewhere and provide a definition for it.<br />
<br />
Thanks!]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 3-2-1 and compatible types]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1547</link>
			<pubDate>Fri, 18 Sep 2020 08:47:40 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5505">getMW</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1547</guid>
			<description><![CDATA[the rule says "All declarations of an object or function shall have compatible types."<br />
<br />
the question is: how do you define "compatible types"?<br />
<br />
-if we think it is similar to MISRA-C:2004 8.4 "If objects or functions are declared more than once their types shall be compatible."<br />
or to MISRA-C:2012 8.3 that says "Compatible versions of the same basic type may be used interchangeably. For example, int, signed and signed int are all equivalent."<br />
=&gt; then we can look at the definition of compatible types defined in C norm (sections 6.1.2.6, 6.5.2, 6.5.3 and 6.5.4 for C90)<br />
<br />
-but C++ norm does not define those compatible types and even more, it says in the Annex C.1 3.9(5) <br />
<blockquote class="mycode_quote"><cite>Quote:</cite>Change: C allows “compatible types” in several places, C++ does not</blockquote>
so what are compatible types in C++? do you use C compatible types even if C++ norm rejects them?<br />
do you use another definition?<br />
<br />
Practical example: on the example given in MISRA-C++ documentation<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>// File a.cpp<br />
extern int32_t a;<br />
// File b.cpp<br />
extern int64_t a;&nbsp;&nbsp; // Non-compliant – not compatible</code></div></div>-do you expect that it is always non compliant, whatever the platform is? (whatever are the size of int32_t and int64_t)<br />
-or can we consider that <ul class="mycode_list"><li>it can be compliant on platform where int32_t and int64_t have same signess and size</li>
</ul>
<ul class="mycode_list"><li>it can be non-compliant on platforms where size are different</li>
</ul>
]]></description>
			<content:encoded><![CDATA[the rule says "All declarations of an object or function shall have compatible types."<br />
<br />
the question is: how do you define "compatible types"?<br />
<br />
-if we think it is similar to MISRA-C:2004 8.4 "If objects or functions are declared more than once their types shall be compatible."<br />
or to MISRA-C:2012 8.3 that says "Compatible versions of the same basic type may be used interchangeably. For example, int, signed and signed int are all equivalent."<br />
=&gt; then we can look at the definition of compatible types defined in C norm (sections 6.1.2.6, 6.5.2, 6.5.3 and 6.5.4 for C90)<br />
<br />
-but C++ norm does not define those compatible types and even more, it says in the Annex C.1 3.9(5) <br />
<blockquote class="mycode_quote"><cite>Quote:</cite>Change: C allows “compatible types” in several places, C++ does not</blockquote>
so what are compatible types in C++? do you use C compatible types even if C++ norm rejects them?<br />
do you use another definition?<br />
<br />
Practical example: on the example given in MISRA-C++ documentation<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>// File a.cpp<br />
extern int32_t a;<br />
// File b.cpp<br />
extern int64_t a;&nbsp;&nbsp; // Non-compliant – not compatible</code></div></div>-do you expect that it is always non compliant, whatever the platform is? (whatever are the size of int32_t and int64_t)<br />
-or can we consider that <ul class="mycode_list"><li>it can be compliant on platform where int32_t and int64_t have same signess and size</li>
</ul>
<ul class="mycode_list"><li>it can be non-compliant on platforms where size are different</li>
</ul>
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 3-4-1 and defining constants in one place]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1444</link>
			<pubDate>Thu, 26 Jul 2018 12:28:24 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5040">rrosier</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1444</guid>
			<description><![CDATA[If one were to use the strategy of defining all the constants used within a file at the top of the file, either as static const or in an unnamed namespace, but some of the constants are used in multiple places and others are only used in single places, then those that are only used in single places will violate Rule 3-4-1.<br />
<br />
If those that are used only in single places are subsequently moved into blocks with reduced scope, then the constants are scattered around the file.<br />
<br />
This could create a maintenance headache because it is more difficult for a developer to find a constant.<br />
<br />
Furthermore, if a developer needs to use a singly-used constant now in another place, they might not realise that the constant has already been defined (and then widen its scope) but instead add in a new singly-used constant of reduced scope in the new place.<br />
<br />
It there some way to put all of the defined constants into a well-known location, but then not violate Rule 3-4-1 for the singly-used ones?]]></description>
			<content:encoded><![CDATA[If one were to use the strategy of defining all the constants used within a file at the top of the file, either as static const or in an unnamed namespace, but some of the constants are used in multiple places and others are only used in single places, then those that are only used in single places will violate Rule 3-4-1.<br />
<br />
If those that are used only in single places are subsequently moved into blocks with reduced scope, then the constants are scattered around the file.<br />
<br />
This could create a maintenance headache because it is more difficult for a developer to find a constant.<br />
<br />
Furthermore, if a developer needs to use a singly-used constant now in another place, they might not realise that the constant has already been defined (and then widen its scope) but instead add in a new singly-used constant of reduced scope in the new place.<br />
<br />
It there some way to put all of the defined constants into a well-known location, but then not violate Rule 3-4-1 for the singly-used ones?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[3-9-2 and auto in future MISRA C++14]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1441</link>
			<pubDate>Fri, 20 Jul 2018 07:32:17 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4389">dg1980</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1441</guid>
			<description><![CDATA[Hi,<br />
<br />
as stated here (<a href="https://misra.org.uk/forum/viewtopic.php?f=183&amp;t=1504#p3404" target="_blank" rel="noopener" class="mycode_url">https://misra.org.uk/forum/viewtopic.php...1504#p3404</a>) the next version of MISRA C++ will be based on ISO C++14.<br />
I am curious if you already came to a decision on whether to allow or prohibit the auto keyword for automatic type deduction?<br />
While it is certainly more convenient to write code, i would imagine performing a code review or adapting a static analysis tool would become more challenging.]]></description>
			<content:encoded><![CDATA[Hi,<br />
<br />
as stated here (<a href="https://misra.org.uk/forum/viewtopic.php?f=183&amp;t=1504#p3404" target="_blank" rel="noopener" class="mycode_url">https://misra.org.uk/forum/viewtopic.php...1504#p3404</a>) the next version of MISRA C++ will be based on ISO C++14.<br />
I am curious if you already came to a decision on whether to allow or prohibit the auto keyword for automatic type deduction?<br />
While it is certainly more convenient to write code, i would imagine performing a code review or adapting a static analysis tool would become more challenging.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 3-9-2 and operator overloading]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1354</link>
			<pubDate>Fri, 30 Jun 2017 09:01:34 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4389">dg1980</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1354</guid>
			<description><![CDATA[Dear MISRA team,<br />
<br />
according to ISO/IEC 14882:2003 chapter 13.5.7 a single int is required to distinguish between prefix and postfix operators:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>class X {<br />
public:<br />
X&amp; operator++(); // prefix ++a<br />
X operator++(int); // postfix a++<br />
};</code></div></div><br />
If you recategorize 3-9-2 as mandatory would the usage of int require a deviation or is it an explicit exception (compare with int main exception in DIR 4.6 of MISRA C 2012) ?<br />
Thanks.]]></description>
			<content:encoded><![CDATA[Dear MISRA team,<br />
<br />
according to ISO/IEC 14882:2003 chapter 13.5.7 a single int is required to distinguish between prefix and postfix operators:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>class X {<br />
public:<br />
X&amp; operator++(); // prefix ++a<br />
X operator++(int); // postfix a++<br />
};</code></div></div><br />
If you recategorize 3-9-2 as mandatory would the usage of int require a deviation or is it an explicit exception (compare with int main exception in DIR 4.6 of MISRA C 2012) ?<br />
Thanks.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 3-4-1 and classes]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1301</link>
			<pubDate>Wed, 21 Dec 2016 10:50:19 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=1787">drstaiger</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1301</guid>
			<description><![CDATA[The rule's title includes "types", but the body of the rule does not specify further whether this is meant for typedefs only, or for complex classes as well.<br />
For example, a class only used in a single function: should it be moved into the function? That would work against the typical ideas of short functions and separation of responsibilities. Could you please clarify MISRA's intention here?]]></description>
			<content:encoded><![CDATA[The rule's title includes "types", but the body of the rule does not specify further whether this is meant for typedefs only, or for complex classes as well.<br />
For example, a class only used in a single function: should it be moved into the function? That would work against the typical ideas of short functions and separation of responsibilities. Could you please clarify MISRA's intention here?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[size_t and Rule 3-9-2]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1130</link>
			<pubDate>Fri, 21 Nov 2014 14:34:02 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=3622">markturney</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1130</guid>
			<description><![CDATA[Hello,<br />
<br />
Rule 3-9-2 states that "typedefs that indicate size and signedness should be used in place of the basic numerical types."<br />
<br />
It specifically states that "The basic numerical types of char, int, short, long, float, double and long double should not be used, but specific-length typedefs should be used."<br />
<br />
What about size_t?  The signedness is known, but the specific-length is not.<br />
<br />
Does this code snippet violate 3-9-2?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>std::vector collection(3, 5);<br />
<br />
for (std::size_t ii = 0, count = collection.size(); ii &lt; count; ++ii)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;processElement(collection[ii]);<br />
}</code></div></div><br />
Thank you for the help,<br />
Mark]]></description>
			<content:encoded><![CDATA[Hello,<br />
<br />
Rule 3-9-2 states that "typedefs that indicate size and signedness should be used in place of the basic numerical types."<br />
<br />
It specifically states that "The basic numerical types of char, int, short, long, float, double and long double should not be used, but specific-length typedefs should be used."<br />
<br />
What about size_t?  The signedness is known, but the specific-length is not.<br />
<br />
Does this code snippet violate 3-9-2?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>std::vector collection(3, 5);<br />
<br />
for (std::size_t ii = 0, count = collection.size(); ii &lt; count; ++ii)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;processElement(collection[ii]);<br />
}</code></div></div><br />
Thank you for the help,<br />
Mark]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 3-4-1 issues]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1122</link>
			<pubDate>Thu, 16 Oct 2014 13:22:14 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=3542">CGeddes</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1122</guid>
			<description><![CDATA[We're having issues complying with rule 3-4-1 in a number of functions that initialise a temporary variable which is subsequently modified and tested within a loop. I appreciate in many cases this can be resolved with recursion, however, it seems an excessive solution given the additional considerations required. <br />
<br />
The only other solution we've found (that doesn't conflict with other rules) is to declare and initialise a struct with the members set to the required values. e.g.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f (void) <br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;struct FOO<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int Index; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int Result;<br />
&nbsp;&nbsp;&nbsp;&nbsp;} ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;for (FOO Test = {0, 0}; Test.Index &lt; 10; Test.Index++)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Test.Result += SomeTestFunction( ); <br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (Test.Result &gt; 5) <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>What is the an 'expected' implementation of such functionality?]]></description>
			<content:encoded><![CDATA[We're having issues complying with rule 3-4-1 in a number of functions that initialise a temporary variable which is subsequently modified and tested within a loop. I appreciate in many cases this can be resolved with recursion, however, it seems an excessive solution given the additional considerations required. <br />
<br />
The only other solution we've found (that doesn't conflict with other rules) is to declare and initialise a struct with the members set to the required values. e.g.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f (void) <br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;struct FOO<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int Index; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int Result;<br />
&nbsp;&nbsp;&nbsp;&nbsp;} ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;for (FOO Test = {0, 0}; Test.Index &lt; 10; Test.Index++)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Test.Result += SomeTestFunction( ); <br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (Test.Result &gt; 5) <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>What is the an 'expected' implementation of such functionality?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 3-2-4 comparison with MISRA C Rule 8.9]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=929</link>
			<pubDate>Thu, 03 Jan 2013 06:59:04 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=2281">sarkarsaurabh_27</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=929</guid>
			<description><![CDATA[<span style="font-weight: bold;" class="mycode_b">An identifier with external linkage shall have exactly one definition.</span><br />
The test exemplar provided with MISRA C for rule 8.9 has <br />
<span style="font-style: italic;" class="mycode_i">// mc2_0809_1.c</span><br />
int32_t two_different_definitions = 1;  /* Not Compliant - two definitions */<br />
<span style="font-style: italic;" class="mycode_i">// mc2_0809_2.c</span><br />
int32_t two_different_definitions = 2;   /* Not Compliant - two definitions */<br />
<span style="font-style: italic;" class="mycode_i">// mc2_0809.h</span><br />
extern int32_t two_different_definitions;<br />
<br />
But the example given in the MISRA C++ Guidelines Draft for Rule 3-2-4 is :<br />
<span style="font-style: italic;" class="mycode_i">// file1.cpp</span><br />
int32_t i = 0;<br />
<span style="font-style: italic;" class="mycode_i">// file2.cpp</span><br />
int32_t i = 1;        // Non-compliant<br />
<br />
As both the rules are some what same, but the difference in the example given is that in rule 3-2-4 no external linkage is provided. Is it an incomplete example or the rule should show violation without having an extern of the variable.]]></description>
			<content:encoded><![CDATA[<span style="font-weight: bold;" class="mycode_b">An identifier with external linkage shall have exactly one definition.</span><br />
The test exemplar provided with MISRA C for rule 8.9 has <br />
<span style="font-style: italic;" class="mycode_i">// mc2_0809_1.c</span><br />
int32_t two_different_definitions = 1;  /* Not Compliant - two definitions */<br />
<span style="font-style: italic;" class="mycode_i">// mc2_0809_2.c</span><br />
int32_t two_different_definitions = 2;   /* Not Compliant - two definitions */<br />
<span style="font-style: italic;" class="mycode_i">// mc2_0809.h</span><br />
extern int32_t two_different_definitions;<br />
<br />
But the example given in the MISRA C++ Guidelines Draft for Rule 3-2-4 is :<br />
<span style="font-style: italic;" class="mycode_i">// file1.cpp</span><br />
int32_t i = 0;<br />
<span style="font-style: italic;" class="mycode_i">// file2.cpp</span><br />
int32_t i = 1;        // Non-compliant<br />
<br />
As both the rules are some what same, but the difference in the example given is that in rule 3-2-4 no external linkage is provided. Is it an incomplete example or the rule should show violation without having an extern of the variable.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[3-9-2 and 'bool']]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=904</link>
			<pubDate>Tue, 12 Jun 2012 14:23:12 +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=904</guid>
			<description><![CDATA[Is rule #3-9-2 intended to apply to the 'bool' type?]]></description>
			<content:encoded><![CDATA[Is rule #3-9-2 intended to apply to the 'bool' type?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 3-9-1]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=870</link>
			<pubDate>Fri, 30 Dec 2011 20:19:34 +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=870</guid>
			<description><![CDATA[The rule states that the types for a function declaration and definition must be token-for-token identical. How literally should this rule be taken. I have two cases where this rule seems to conflict with normal or good practice.<br />
<br />
1. In a function definition, a 'const' qualifier is often included for parameters passed by value as a promise that the implementation will not modify these parameters. This qualifier cannot be included in the declaration. For example:<br />
<br />
template <br />
T low_bits_mask(unsigned n);<br />
<br />
template <br />
T low_bits_mask(const unsigned n) {<br />
  return ~((~static_cast(0)) ]]></description>
			<content:encoded><![CDATA[The rule states that the types for a function declaration and definition must be token-for-token identical. How literally should this rule be taken. I have two cases where this rule seems to conflict with normal or good practice.<br />
<br />
1. In a function definition, a 'const' qualifier is often included for parameters passed by value as a promise that the implementation will not modify these parameters. This qualifier cannot be included in the declaration. For example:<br />
<br />
template <br />
T low_bits_mask(unsigned n);<br />
<br />
template <br />
T low_bits_mask(const unsigned n) {<br />
  return ~((~static_cast(0)) ]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 3-2-3 and friend Declarations]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=777</link>
			<pubDate>Thu, 30 Sep 2010 16:28:19 +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=777</guid>
			<description><![CDATA[Am I correct in presuming rule 3-2-3 does not apply to friend declarations?  For example, if I declare a class type in a header file, am I permitted to declare that class as a friend of another type in a different file?]]></description>
			<content:encoded><![CDATA[Am I correct in presuming rule 3-2-3 does not apply to friend declarations?  For example, if I declare a class type in a header file, am I permitted to declare that class as a friend of another type in a different file?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule #3-2-3 and Forward Declarations?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=766</link>
			<pubDate>Wed, 18 Aug 2010 19:05:22 +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=766</guid>
			<description><![CDATA[Does rule #3-2-3 prohibit the use of forward declarations in separate files?  For example, if a file, a.h, contained "class B;" and another file, c.h, #include'd a.h <span style="font-style: italic;" class="mycode_i">and</span> contained a definition for class D which contained "friend class B;", would the rule permit such?]]></description>
			<content:encoded><![CDATA[Does rule #3-2-3 prohibit the use of forward declarations in separate files?  For example, if a file, a.h, contained "class B;" and another file, c.h, #include'd a.h <span style="font-style: italic;" class="mycode_i">and</span> contained a definition for class D which contained "friend class B;", would the rule permit such?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 3-1-1 and constant declarations]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=691</link>
			<pubDate>Wed, 18 Nov 2009 18:08:32 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=878">MarkCotton</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=691</guid>
			<description><![CDATA[I have been using PCLint to analyse code which have constants defined in header files e.g.<br />
<br />
const uint8 PLD_READ_VERIFICATION_BYTE_4 = 7;<br />
<br />
PCLint claims that this violates rule 3-1-1. Is this a true interpretation of this rule or are constants permitted in header files?<br />
<br />
Mark.]]></description>
			<content:encoded><![CDATA[I have been using PCLint to analyse code which have constants defined in header files e.g.<br />
<br />
const uint8 PLD_READ_VERIFICATION_BYTE_4 = 7;<br />
<br />
PCLint claims that this violates rule 3-1-1. Is this a true interpretation of this rule or are constants permitted in header files?<br />
<br />
Mark.]]></content:encoded>
		</item>
	</channel>
</rss>