<?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.20 Preprocessing directives]]></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:43 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[20.12 Does the stringification really matter?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1778</link>
			<pubDate>Tue, 07 Jul 2026 09:59:02 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6753">Loïc</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1778</guid>
			<description><![CDATA[Hello,<br />
<br />
While looking at violations of 20.12 <span style="font-style: italic;" class="mycode_i">A macro parameter used as an operand to the "#" or "##" operators, which is itself subject to further macro replacement, shall only be used as an operand to these operators</span>, I discovered that most of them were of the form:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>assert(value &lt; LIMIT)</code></div></div><br />
Indeed, the macro parameter of <span style="font-weight: bold;" class="mycode_b">assert</span> is typically stringified, and in that case it contains the macro <span style="font-weight: bold;" class="mycode_b">LIMIT </span>that is itself subject to further replacement.<br />
<br />
However, I don't see the safety case for this violation. The fact that the unexpended version of the macro will appear in the string is exactly what is needed.<br />
<br />
I agree that with token pasting (<span style="font-weight: bold;" class="mycode_b">##</span>), this situation could lead to hard to understand code, but not with stringification.<br />
<br />
FWIW, I discussed this with MISRA C++ (that contains the same rule), and the sentiment of the group was that the rule should be updated to remove the stringification part.<br />
<br />
<br />
What do you think?]]></description>
			<content:encoded><![CDATA[Hello,<br />
<br />
While looking at violations of 20.12 <span style="font-style: italic;" class="mycode_i">A macro parameter used as an operand to the "#" or "##" operators, which is itself subject to further macro replacement, shall only be used as an operand to these operators</span>, I discovered that most of them were of the form:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>assert(value &lt; LIMIT)</code></div></div><br />
Indeed, the macro parameter of <span style="font-weight: bold;" class="mycode_b">assert</span> is typically stringified, and in that case it contains the macro <span style="font-weight: bold;" class="mycode_b">LIMIT </span>that is itself subject to further replacement.<br />
<br />
However, I don't see the safety case for this violation. The fact that the unexpended version of the macro will appear in the string is exactly what is needed.<br />
<br />
I agree that with token pasting (<span style="font-weight: bold;" class="mycode_b">##</span>), this situation could lead to hard to understand code, but not with stringification.<br />
<br />
FWIW, I discussed this with MISRA C++ (that contains the same rule), and the sentiment of the group was that the rule should be updated to remove the stringification part.<br />
<br />
<br />
What do you think?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[MISRA C:2012 Rule 20.5 applicable for inactive code ?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1521</link>
			<pubDate>Mon, 06 Jan 2020 13:43:19 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=3107">Girish</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1521</guid>
			<description><![CDATA[Hello,<br />
<br />
MISRA C:2012 Rule 20.5 -  #undef should not be used.<br />
<br />
For the following code snippet, #undef is seen at line 5 and 8.<br />
As Rule 20.5 complains for use of #undef, please let us know whether code at line 8, which is inactive code due to #else is Non-compliant  or not according MISRA C:2012 Rule 20.5 ?<br />
<br />
<br />
1. #define FLAG 100<br />
2.<br />
3. #ifdef FLAG<br />
4.     #define  L      0<br />
5.   #undef   L <br />
6. #else<br />
7.    #define X 0<br />
8.   #undef X <br />
9. #endif  <br />
<br />
Regards<br />
Girish.M]]></description>
			<content:encoded><![CDATA[Hello,<br />
<br />
MISRA C:2012 Rule 20.5 -  #undef should not be used.<br />
<br />
For the following code snippet, #undef is seen at line 5 and 8.<br />
As Rule 20.5 complains for use of #undef, please let us know whether code at line 8, which is inactive code due to #else is Non-compliant  or not according MISRA C:2012 Rule 20.5 ?<br />
<br />
<br />
1. #define FLAG 100<br />
2.<br />
3. #ifdef FLAG<br />
4.     #define  L      0<br />
5.   #undef   L <br />
6. #else<br />
7.    #define X 0<br />
8.   #undef X <br />
9. #endif  <br />
<br />
Regards<br />
Girish.M]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 20.2]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1405</link>
			<pubDate>Thu, 08 Mar 2018 15:06:26 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=1183">kalpak</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1405</guid>
			<description><![CDATA[Why is<br />
<span style="font-weight: bold;" class="mycode_b">#include  "c:\headers\measurement_regs.h " </span><br />
non compliant to rule 20.2 due to <span style="font-weight: bold;" class="mycode_b">\</span> in the path?]]></description>
			<content:encoded><![CDATA[Why is<br />
<span style="font-weight: bold;" class="mycode_b">#include  "c:\headers\measurement_regs.h " </span><br />
non compliant to rule 20.2 due to <span style="font-weight: bold;" class="mycode_b">\</span> in the path?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 20.8 and #elif]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1385</link>
			<pubDate>Wed, 01 Nov 2017 16:03:37 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=318">rgamble</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1385</guid>
			<description><![CDATA[It is pretty clear from the Amplification that this is not a violation of Rule 20.8:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#if 0<br />
&nbsp;&nbsp;#if 10&nbsp;&nbsp;/* not evaluated, not a violation */<br />
&nbsp;&nbsp;#endif<br />
#endif</code></div></div>and that this is:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#if 0<br />
#elif 20&nbsp;&nbsp;/* evaluated, violation */<br />
#endif</code></div></div>but is the following intended to be a violation of this rule?:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#if 1<br />
#elif 20&nbsp;&nbsp;/* ??? */<br />
#endif</code></div></div>It is not clear if the preprocessing directive <span style="font-weight: bold;" class="mycode_b">#elif 20</span> is <span style="font-style: italic;" class="mycode_i">evaluated</span> for the purpose of this rule.]]></description>
			<content:encoded><![CDATA[It is pretty clear from the Amplification that this is not a violation of Rule 20.8:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#if 0<br />
&nbsp;&nbsp;#if 10&nbsp;&nbsp;/* not evaluated, not a violation */<br />
&nbsp;&nbsp;#endif<br />
#endif</code></div></div>and that this is:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#if 0<br />
#elif 20&nbsp;&nbsp;/* evaluated, violation */<br />
#endif</code></div></div>but is the following intended to be a violation of this rule?:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#if 1<br />
#elif 20&nbsp;&nbsp;/* ??? */<br />
#endif</code></div></div>It is not clear if the preprocessing directive <span style="font-weight: bold;" class="mycode_b">#elif 20</span> is <span style="font-style: italic;" class="mycode_i">evaluated</span> for the purpose of this rule.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Clarification on Rule 20.8]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1162</link>
			<pubDate>Thu, 05 Mar 2015 12:47:47 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=3719">anuj1085</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1162</guid>
			<description><![CDATA[In the below case<br />
<br />
#if 10<br />
----<br />
#elif 20<br />
----<br />
#endif<br />
<br />
Since the part of the code<br />
 #elif 20<br />
----<br />
#endif<br />
<br />
Is never gonna execute, is the rule applicable to this part of code i.e the part #elif 20 will be ignored while compilation so should the violation should be reported on it ?]]></description>
			<content:encoded><![CDATA[In the below case<br />
<br />
#if 10<br />
----<br />
#elif 20<br />
----<br />
#endif<br />
<br />
Since the part of the code<br />
 #elif 20<br />
----<br />
#endif<br />
<br />
Is never gonna execute, is the rule applicable to this part of code i.e the part #elif 20 will be ignored while compilation so should the violation should be reported on it ?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 20.3 space after #include]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1150</link>
			<pubDate>Fri, 13 Feb 2015 12:36:50 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=196">misra-c</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1150</guid>
			<description><![CDATA[The amplification to rule 20.3 states that the rule applies "after macro replacement" has been performed. Is the number/absence of spaces and comments between #include and the " or &lt;  irrelevant?  <br />
<br />
So for example: <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* no space - compliant ? */<br />
#include/* comment*/&nbsp;&nbsp;/* compliant&nbsp;&nbsp;? */.</code></div></div>]]></description>
			<content:encoded><![CDATA[The amplification to rule 20.3 states that the rule applies "after macro replacement" has been performed. Is the number/absence of spaces and comments between #include and the " or &lt;  irrelevant?  <br />
<br />
So for example: <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* no space - compliant ? */<br />
#include/* comment*/&nbsp;&nbsp;/* compliant&nbsp;&nbsp;? */.</code></div></div>]]></content:encoded>
		</item>
	</channel>
</rss>