<?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.2 Lexical conventions (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 20:03:05 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[2-10-2 "block scope" for classes and namespaces]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1470</link>
			<pubDate>Thu, 14 Feb 2019 11:11:21 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4847">abgs</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1470</guid>
			<description><![CDATA[Rule 2-10-2 is defined in terms of "block scopes" and "nested blocks". The only example is of a function and there is no mention of classes nor namespaces. Does "block" refer only to a compound statement as part of a function body, or is the intention to include other curly-brace-enclosed regions or scopes? For example, are any of the indicated lines violations of rule 2-10-2?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>int i;<br />
namespace n { int i; } // A<br />
namespace { int i; } // B<br />
class c { int i; }; // C<br />
<br />
class c2 { int k; void f() { int k; } }; // D<br />
<br />
class base { int z; };<br />
class derived : public base { int z; }; // E</code></div></div>]]></description>
			<content:encoded><![CDATA[Rule 2-10-2 is defined in terms of "block scopes" and "nested blocks". The only example is of a function and there is no mention of classes nor namespaces. Does "block" refer only to a compound statement as part of a function body, or is the intention to include other curly-brace-enclosed regions or scopes? For example, are any of the indicated lines violations of rule 2-10-2?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>int i;<br />
namespace n { int i; } // A<br />
namespace { int i; } // B<br />
class c { int i; }; // C<br />
<br />
class c2 { int k; void f() { int k; } }; // D<br />
<br />
class base { int z; };<br />
class derived : public base { int z; }; // E</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Difference between 2-10-2 and MISRA C-2012 Rule 5.3]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1455</link>
			<pubDate>Wed, 19 Sep 2018 06:04:32 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=3849">cxlin</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1455</guid>
			<description><![CDATA[Hi,<br />
<br />
MISRA C-2012 Rule 5.3 (which is of the same title as 2-10-2) has this additional amplification about an identifier declared in an inner scope shall be distinct from *any* id declared in an outer scope.<br />
<br />
So the following code shall be a violation for 5.3 although the inner "i" is not hiding the outer "i" (still confusing though).<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int i; // Non-compliant<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;int i;<br />
}</code></div></div><br />
Since 2-10-2 does not have this amplification, could you kindly help to advise whether this is also a violation for 2-10-2 or not?]]></description>
			<content:encoded><![CDATA[Hi,<br />
<br />
MISRA C-2012 Rule 5.3 (which is of the same title as 2-10-2) has this additional amplification about an identifier declared in an inner scope shall be distinct from *any* id declared in an outer scope.<br />
<br />
So the following code shall be a violation for 5.3 although the inner "i" is not hiding the outer "i" (still confusing though).<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int i; // Non-compliant<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;int i;<br />
}</code></div></div><br />
Since 2-10-2 does not have this amplification, could you kindly help to advise whether this is also a violation for 2-10-2 or not?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 2-5-1]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1374</link>
			<pubDate>Sun, 01 Oct 2017 01:31:16 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=114">ogawa.kiyoshi</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1374</guid>
			<description><![CDATA[I feel, the sentence  "The use of digraphs may not meet developer expectations." is not clear.<br />
The usage of digraphs are only system constraints. <br />
Digraph are just an alternative method for a systems that can not input '{','}','[',']'. <br />
Therefore, there is no point in leaving a digraph in the final source file. <br />
Even if anyone use a system that requires digraphs, it is better to replace in the final source file from digraph(alternative token) to primary token.]]></description>
			<content:encoded><![CDATA[I feel, the sentence  "The use of digraphs may not meet developer expectations." is not clear.<br />
The usage of digraphs are only system constraints. <br />
Digraph are just an alternative method for a systems that can not input '{','}','[',']'. <br />
Therefore, there is no point in leaving a digraph in the final source file. <br />
Even if anyone use a system that requires digraphs, it is better to replace in the final source file from digraph(alternative token) to primary token.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[2-10-1 No "overlapping visibility" restriction?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1326</link>
			<pubDate>Thu, 16 Mar 2017 14:14:38 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=3331">grunwald</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1326</guid>
			<description><![CDATA[C 2012 Directive 4.5: "Identifiers in the same name space with overlapping visibility should be typographically unambiguous"<br />
C++ Rule 2-10-1: "Different identifiers shall be typographically unambiguous."<br />
<br />
Does this mean the C++ rule applies even to identifiers in different scopes?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f1() { int i; }<br />
void f2() { int I; } // 2-10-1 violation due to only differing in case?</code></div></div><br />
Also, does the C++ rule forbid naming a variables after their class name?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>class MyClass { };<br />
MyClass myClass;&nbsp;&nbsp;// 2-10-1 violation?</code></div></div>]]></description>
			<content:encoded><![CDATA[C 2012 Directive 4.5: "Identifiers in the same name space with overlapping visibility should be typographically unambiguous"<br />
C++ Rule 2-10-1: "Different identifiers shall be typographically unambiguous."<br />
<br />
Does this mean the C++ rule applies even to identifiers in different scopes?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void f1() { int i; }<br />
void f2() { int I; } // 2-10-1 violation due to only differing in case?</code></div></div><br />
Also, does the C++ rule forbid naming a variables after their class name?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>class MyClass { };<br />
MyClass myClass;&nbsp;&nbsp;// 2-10-1 violation?</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Did '\000' and 000 comply with Rule 2-13-2]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1318</link>
			<pubDate>Tue, 28 Feb 2017 06:09:09 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4686">longfem</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1318</guid>
			<description><![CDATA[Dears,<br />
Rule 2-10-3 said that Octal constants (other than zero) and octal escape sequences (other than â€œ\0â€) shall not be used.<br />
<br />
From the description we know that '\0' and 0 comply with the rule.<br />
How about '\00',  '\000' , 00 and 000 ?<br />
<br />
Thanks,<br />
Longfem]]></description>
			<content:encoded><![CDATA[Dears,<br />
Rule 2-10-3 said that Octal constants (other than zero) and octal escape sequences (other than â€œ\0â€) shall not be used.<br />
<br />
From the description we know that '\0' and 0 comply with the rule.<br />
How about '\00',  '\000' , 00 and 000 ?<br />
<br />
Thanks,<br />
Longfem]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 2-10-5 is totaly ambiguous]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1246</link>
			<pubDate>Sun, 15 May 2016 05:36:38 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=4420">udi</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1246</guid>
			<description><![CDATA[Hello,<br />
<br />
I think this rule should be rephrased (or maybe split) for clarity, and giving some more examples.<br />
Problems are:<br />
1. As already mentioned - function overloading.<br />
<br />
2. It is not clear whether static variables inside function are violating this rule:<br />
    void f1() { static int nFoo; }<br />
    void f2() { static int nFoo; }<br />
I think it does not violate (also based on my exmaples from MISRA C-2012 Rule 5.9) but my static analysis tool, thinks it does.<br />
<br />
3. Do static class members violate this rule?<br />
    class C1 { public: static int nNumOfItems; }<br />
    class C2 { public: static int nNumOfItems; }<br />
I think it does not.<br />
<br />
To my understanding, this rule comes to cover 2 cases (which should be properly explained in the rationale):<br />
1. Hiding of identifier in an internal scope<br />
2. Conusion of 2 global static identifiers with the same name (whose scope is actualy indipendantly limited to each .cpp file)<br />
<br />
Thanks,<br />
Udi.]]></description>
			<content:encoded><![CDATA[Hello,<br />
<br />
I think this rule should be rephrased (or maybe split) for clarity, and giving some more examples.<br />
Problems are:<br />
1. As already mentioned - function overloading.<br />
<br />
2. It is not clear whether static variables inside function are violating this rule:<br />
    void f1() { static int nFoo; }<br />
    void f2() { static int nFoo; }<br />
I think it does not violate (also based on my exmaples from MISRA C-2012 Rule 5.9) but my static analysis tool, thinks it does.<br />
<br />
3. Do static class members violate this rule?<br />
    class C1 { public: static int nNumOfItems; }<br />
    class C2 { public: static int nNumOfItems; }<br />
I think it does not.<br />
<br />
To my understanding, this rule comes to cover 2 cases (which should be properly explained in the rationale):<br />
1. Hiding of identifier in an internal scope<br />
2. Conusion of 2 global static identifiers with the same name (whose scope is actualy indipendantly limited to each .cpp file)<br />
<br />
Thanks,<br />
Udi.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 2-10-6]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1223</link>
			<pubDate>Tue, 26 Jan 2016 09:04:38 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=109">Mats Fors</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1223</guid>
			<description><![CDATA[Shouldn't example one be compliant?<br />
<br />
typedef struct vector {...} vector;<br />
<br />
The two vector identifiers are both referring to the same type.]]></description>
			<content:encoded><![CDATA[Shouldn't example one be compliant?<br />
<br />
typedef struct vector {...} vector;<br />
<br />
The two vector identifiers are both referring to the same type.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 2-10-5 and function overloading]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=560</link>
			<pubDate>Wed, 23 Jul 2008 16:26:01 +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=560</guid>
			<description><![CDATA[Hello, <br />
<br />
does rule 2-10-5 disallows function overloading? What is the definition of "identifier reuse"? <br />
For example:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>class C{}; <br />
void foo(int);<br />
void foo(C);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Not compliant?<br />
void foo(int, C); // Not compliant?</code></div></div>]]></description>
			<content:encoded><![CDATA[Hello, <br />
<br />
does rule 2-10-5 disallows function overloading? What is the definition of "identifier reuse"? <br />
For example:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>class C{}; <br />
void foo(int);<br />
void foo(C);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Not compliant?<br />
void foo(int, C); // Not compliant?</code></div></div>]]></content:encoded>
		</item>
	</channel>
</rss>