<?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.14 Control Flow]]></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:12:57 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[Loops violate Rule 14.3]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1183</link>
			<pubDate>Tue, 02 Jun 2015 10:20:04 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=3709">chrisT</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1183</guid>
			<description><![CDATA[Hello.<br />
<br />
In our company, we have developers who uses <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>for(;;)</code></div></div> loops. Are these a violation against rule 14.3?<br />
<br />
kind regards.]]></description>
			<content:encoded><![CDATA[Hello.<br />
<br />
In our company, we have developers who uses <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>for(;;)</code></div></div> loops. Are these a violation against rule 14.3?<br />
<br />
kind regards.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 14.3 and null macros]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=846</link>
			<pubDate>Wed, 14 Sep 2011 07:20:43 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=1743">JohnC</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=846</guid>
			<description><![CDATA[If a function is sometimes to be included and sometimes omitted, the classic solution is to define it like this:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#if FnIsWanted<br />
&nbsp;&nbsp;extern void Fn( void );<br />
#else<br />
&nbsp;&nbsp;#define Fn( ) <br />
#endif</code></div></div><br />
As already noted, this falls foul of rule 14.3, though primarily it is a breach of rule 19.4 (what a macro can be defined as).<br />
<br />
I can get the the effect I want on my compiler without apparently breaching MISRA rules by using the following alternative:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#if FnIsWanted<br />
&nbsp;&nbsp;extern void Fn( void );<br />
#else<br />
&nbsp;&nbsp;#define Fn( ) do{}while(0)<br />
#endif</code></div></div><br />
However, the body of this do-while is a null (compound) statement, so has my compiler missed a violation?]]></description>
			<content:encoded><![CDATA[If a function is sometimes to be included and sometimes omitted, the classic solution is to define it like this:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#if FnIsWanted<br />
&nbsp;&nbsp;extern void Fn( void );<br />
#else<br />
&nbsp;&nbsp;#define Fn( ) <br />
#endif</code></div></div><br />
As already noted, this falls foul of rule 14.3, though primarily it is a breach of rule 19.4 (what a macro can be defined as).<br />
<br />
I can get the the effect I want on my compiler without apparently breaching MISRA rules by using the following alternative:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#if FnIsWanted<br />
&nbsp;&nbsp;extern void Fn( void );<br />
#else<br />
&nbsp;&nbsp;#define Fn( ) do{}while(0)<br />
#endif</code></div></div><br />
However, the body of this do-while is a null (compound) statement, so has my compiler missed a violation?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[what means about "Before preprocessing" in Rule[14.3]]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=745</link>
			<pubDate>Wed, 23 Jun 2010 12:33:02 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=1090">linglingma</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=745</guid>
			<description><![CDATA["Before preprocessing, a null statement shall only occur on a <br />
line by itself; it may be followed by a comment provided that<br />
the first character following the null statement is a white-space<br />
character." in this rule,why "Before preprocessing"is used as a condition?<br />
Thanks!]]></description>
			<content:encoded><![CDATA["Before preprocessing, a null statement shall only occur on a <br />
line by itself; it may be followed by a comment provided that<br />
the first character following the null statement is a white-space<br />
character." in this rule,why "Before preprocessing"is used as a condition?<br />
Thanks!]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 14.3]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=718</link>
			<pubDate>Wed, 17 Mar 2010 15:50:26 +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=718</guid>
			<description><![CDATA[Hi, <br />
I am running into this rule whenever using in-line assemebly in my blackfin project.<br />
<br />
i.e<br />
<br />
asm ("ssync;");<br />
or <br />
asm("nop;");<br />
<br />
generated the error in ibm logiscope <br />
"A null statements shall only occur on a line by itself, and shall not have any other text on the same line"<br />
<br />
I assume this comes from having the two ";" characters on the one line.<br />
But how can i overcome this?<br />
<br />
Matthew]]></description>
			<content:encoded><![CDATA[Hi, <br />
I am running into this rule whenever using in-line assemebly in my blackfin project.<br />
<br />
i.e<br />
<br />
asm ("ssync;");<br />
or <br />
asm("nop;");<br />
<br />
generated the error in ibm logiscope <br />
"A null statements shall only occur on a line by itself, and shall not have any other text on the same line"<br />
<br />
I assume this comes from having the two ";" characters on the one line.<br />
But how can i overcome this?<br />
<br />
Matthew]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[14.10  /* no else needed */]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=682</link>
			<pubDate>Thu, 22 Oct 2009 13:15:11 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=887">ABR</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=682</guid>
			<description><![CDATA[In rule 14.10 (all if..... else if constructs shall be terminated with an else clause":<br />
<br />
is the /* no else needed */ comment on the single if block with no else a suggestion for use in code, where seems useful?]]></description>
			<content:encoded><![CDATA[In rule 14.10 (all if..... else if constructs shall be terminated with an else clause":<br />
<br />
is the /* no else needed */ comment on the single if block with no else a suggestion for use in code, where seems useful?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[14.10 Hiding an else if construct]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=579</link>
			<pubDate>Wed, 10 Sep 2008 12:13:38 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=671">brian_bassil</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=579</guid>
			<description><![CDATA[The following <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>if ( x &lt; 0 )<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;log_error(3);<br />
&nbsp;&nbsp;&nbsp;&nbsp;x = 0;<br />
}<br />
else if ( y &lt; 0 )<br />
{<br />
&nbsp;&nbsp; x = 3;<br />
}<br />
else<br />
{<br />
/* no change */<br />
}</code></div></div><br />
Can be coded as<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>if ( x &lt; 0 )<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;log_error(3);<br />
&nbsp;&nbsp;&nbsp;&nbsp;x = 0;<br />
}<br />
else <br />
{<br />
&nbsp;&nbsp; if ( y &lt; 0 )<br />
&nbsp;&nbsp; {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x = 3;<br />
&nbsp;&nbsp; }<br />
}</code></div></div><br />
to hide the "else if". Is this OK? <br />
<br />
I think the code blocks are semantically identical but the last one does not list the else.<br />
<br />
Brian]]></description>
			<content:encoded><![CDATA[The following <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>if ( x &lt; 0 )<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;log_error(3);<br />
&nbsp;&nbsp;&nbsp;&nbsp;x = 0;<br />
}<br />
else if ( y &lt; 0 )<br />
{<br />
&nbsp;&nbsp; x = 3;<br />
}<br />
else<br />
{<br />
/* no change */<br />
}</code></div></div><br />
Can be coded as<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>if ( x &lt; 0 )<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;log_error(3);<br />
&nbsp;&nbsp;&nbsp;&nbsp;x = 0;<br />
}<br />
else <br />
{<br />
&nbsp;&nbsp; if ( y &lt; 0 )<br />
&nbsp;&nbsp; {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x = 3;<br />
&nbsp;&nbsp; }<br />
}</code></div></div><br />
to hide the "else if". Is this OK? <br />
<br />
I think the code blocks are semantically identical but the last one does not list the else.<br />
<br />
Brian]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[14.1 There shall be no unreachable code]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=404</link>
			<pubDate>Wed, 24 Oct 2007 07:27:41 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=407">Frank Haug</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=404</guid>
			<description><![CDATA[The wording of 14.1 does not clarify the issue clear enough. I've discussed with several experienced persons and the common of these discussions is, that the questions only can be resolved, if someone ADDS personal interpretations. That cannot be the intension of a rule (text).<br />
<br />
Firstly, \"defensive programming\" is not a misra rule. In my opinion this is a severe lack in/on the misra rule set. Although not explicitly defined its used in the rule text of 14.1 and its used in a confusing way: \"Code that can be reached but may never be executed is excluded from the rule (e.g. defensive programming)\". <br />
<br />
In my tries to understand this, I refactored this sentence on following part (and nobody out of my discussions with Developers and QA Managers could give me an answer on that): <br />
<br />
What is \"code, that can be reached but (may) never be executed\" ?<br />
<br />
The provided example does not answer this question, because it shows code that \"exists but never will be reached\".<br />
<br />
Maybe it helps to concretesize my intention when I re-word above sentence as follows: \"Is it possible, that code can be reached but not executed ?\"<br />
<br />
Thanks in advance<br />
<br />
Frank]]></description>
			<content:encoded><![CDATA[The wording of 14.1 does not clarify the issue clear enough. I've discussed with several experienced persons and the common of these discussions is, that the questions only can be resolved, if someone ADDS personal interpretations. That cannot be the intension of a rule (text).<br />
<br />
Firstly, \"defensive programming\" is not a misra rule. In my opinion this is a severe lack in/on the misra rule set. Although not explicitly defined its used in the rule text of 14.1 and its used in a confusing way: \"Code that can be reached but may never be executed is excluded from the rule (e.g. defensive programming)\". <br />
<br />
In my tries to understand this, I refactored this sentence on following part (and nobody out of my discussions with Developers and QA Managers could give me an answer on that): <br />
<br />
What is \"code, that can be reached but (may) never be executed\" ?<br />
<br />
The provided example does not answer this question, because it shows code that \"exists but never will be reached\".<br />
<br />
Maybe it helps to concretesize my intention when I re-word above sentence as follows: \"Is it possible, that code can be reached but not executed ?\"<br />
<br />
Thanks in advance<br />
<br />
Frank]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Macros & 14.3 II]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=403</link>
			<pubDate>Mon, 22 Oct 2007 14:51:45 +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=403</guid>
			<description><![CDATA[Since, according to <a href="http://www.misra-c2.com/forum/viewtopic.php?t=264" target="_blank" rel="noopener" class="mycode_url">http://www.misra-c2.com/forum/viewtopic.php?t=264</a>, the following code is not permitted:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#if debugging<br />
#define ASSERT(x)&nbsp;&nbsp;&nbsp;&nbsp;asserttest(x)<br />
#else<br />
#define ASSERT(x)<br />
#endif<br />
<br />
void f(int *p)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;ASSERT(p != 0);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</code></div></div><br />
How would one make code well formed with respect to assertion macros?]]></description>
			<content:encoded><![CDATA[Since, according to <a href="http://www.misra-c2.com/forum/viewtopic.php?t=264" target="_blank" rel="noopener" class="mycode_url">http://www.misra-c2.com/forum/viewtopic.php?t=264</a>, the following code is not permitted:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#if debugging<br />
#define ASSERT(x)&nbsp;&nbsp;&nbsp;&nbsp;asserttest(x)<br />
#else<br />
#define ASSERT(x)<br />
#endif<br />
<br />
void f(int *p)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;ASSERT(p != 0);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</code></div></div><br />
How would one make code well formed with respect to assertion macros?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Goto to simulate Exceptions]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=368</link>
			<pubDate>Mon, 25 Jun 2007 11:15:12 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=293">ylehman</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=368</guid>
			<description><![CDATA[There is a typical paradign where each routine returns a status, and on every call that status is checked. If the status is not \"OK\" then the function call stops, and returns to the calling function. There too, the functions checks the status and returns to it's caller and so on till as some point some function (the exception handler) checks the status and does something about it.<br />
<br />
In this way when a error (exception) happens execution stops at that point and the stack is \"unwound\" till the point that it is handled.<br />
<br />
In the \"new\" languages this is achieved using exceptions.<br />
<br />
In C there are two typical ways of doing this - the \"return\" method and the \"if\" method;<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>status&nbsp;&nbsp; foo(&nbsp;&nbsp;&nbsp;&nbsp;)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status st = OK;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; st = bar_aaa(&nbsp;&nbsp; );<br />
&nbsp;&nbsp;&nbsp;&nbsp; if (st == OK) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; st = bar_bbb(&nbsp;&nbsp; ); }<br />
&nbsp;&nbsp;&nbsp;&nbsp; if (st == OK) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; st = bar_ccc(&nbsp;&nbsp; ); }<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;return st;<br />
}</code></div></div><br />
Or this<br />
   <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>status&nbsp;&nbsp; foo(&nbsp;&nbsp;&nbsp;&nbsp;)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status st = OK;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; st = bar_aaa(&nbsp;&nbsp; );<br />
&nbsp;&nbsp;&nbsp;&nbsp; if (st != OK) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return st;<br />
&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; st = bar_bbb(&nbsp;&nbsp; );<br />
&nbsp;&nbsp;&nbsp;&nbsp; if (st != OK) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return st;<br />
&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp; st = bar_ccc(&nbsp;&nbsp; );<br />
&nbsp;&nbsp;&nbsp;&nbsp; if (st != OK) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return st;<br />
&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp;return st;<br />
&nbsp;&nbsp;}</code></div></div><br />
<br />
A much cleaner method that I've been using for many years is as follows:<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>status&nbsp;&nbsp; foo(&nbsp;&nbsp;&nbsp;&nbsp;)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status st = OK;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; st = bar_aaa(&nbsp;&nbsp; ); ER_CHK(st);<br />
&nbsp;&nbsp;&nbsp;&nbsp; st = bar_bbb(&nbsp;&nbsp; ); ER_CHK(st);<br />
&nbsp;&nbsp;&nbsp;&nbsp; st = bar_ccc(&nbsp;&nbsp; ); ER_CHK(st);<br />
 <br />
ER_EXIT:<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;return st;<br />
<br />
}</code></div></div><br />
ER_CHK is a macro that is defined as follows: (simplified)<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define ER_CHK(st) if (st != OK) goto ER_EXIT; else ;</code></div></div><br />
<br />
However the use of the \"goto\" makes people shudder and point to appropriate section in MISRA - though shall not GOTO<br />
<br />
My question<br />
<br />
Is such a use of GOTO allowed ? <br />
Justification:<br />
<br />
  1. The GOTO is hidden in a macro and execution proceeds to a well defined point - this is as structured as the the jump commands behind the  f,while, switch - and yes - break statements. It is better than the break since the destination is well known<br />
<br />
2. The ER_CHK macro can be viewed as an extension of C<br />
<br />
3. It provides a single exit point. This is a major problem in the \"return\" method since if there is a resource to release it needs to be done before each return.<br />
<br />
4. The code is MUCH cleaner and robust<br />
<br />
5. The actual goto was outlawed because it's use lead to a mess - this  use <span style="font-style: italic;" class="mycode_i">prevents </span>the mess - and is more robust since the programmer does not deal with the \"ifs\" and \"returns\" - so can't introduce bugs by doing it wrongly ( \"=\" vs \"==\" bugs, no bug fogetting the \"return\" or doing cleanup before the return etc.)<br />
<br />
6. ER_CHK is actully defined as <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define ER_CHK(st) if (st != OK)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {write_to_log(__LINE__, __FILE__); goto ER_EXIT; else ;</code></div></div><br />
So the log contains something like<br />
<br />
foo1.c (23) status = 3;<br />
foo2.c (125) status = 3;<br />
foo3.c (13) status = 3;<br />
<br />
Where a function in foo3.c on line 13 calls a function in foo2.c on line 125 etc.<br />
<br />
Even C++, Jave exceptions don't do that !!<br />
<br />
The attatched article provides more details and shows an implementation that is CPU and Memory efficient.<br />
<br />
Again - the quesion I'm asking is that the use of this mechanism illegal in MISRA ?]]></description>
			<content:encoded><![CDATA[There is a typical paradign where each routine returns a status, and on every call that status is checked. If the status is not \"OK\" then the function call stops, and returns to the calling function. There too, the functions checks the status and returns to it's caller and so on till as some point some function (the exception handler) checks the status and does something about it.<br />
<br />
In this way when a error (exception) happens execution stops at that point and the stack is \"unwound\" till the point that it is handled.<br />
<br />
In the \"new\" languages this is achieved using exceptions.<br />
<br />
In C there are two typical ways of doing this - the \"return\" method and the \"if\" method;<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>status&nbsp;&nbsp; foo(&nbsp;&nbsp;&nbsp;&nbsp;)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status st = OK;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; st = bar_aaa(&nbsp;&nbsp; );<br />
&nbsp;&nbsp;&nbsp;&nbsp; if (st == OK) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; st = bar_bbb(&nbsp;&nbsp; ); }<br />
&nbsp;&nbsp;&nbsp;&nbsp; if (st == OK) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; st = bar_ccc(&nbsp;&nbsp; ); }<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;return st;<br />
}</code></div></div><br />
Or this<br />
   <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>status&nbsp;&nbsp; foo(&nbsp;&nbsp;&nbsp;&nbsp;)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status st = OK;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; st = bar_aaa(&nbsp;&nbsp; );<br />
&nbsp;&nbsp;&nbsp;&nbsp; if (st != OK) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return st;<br />
&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; st = bar_bbb(&nbsp;&nbsp; );<br />
&nbsp;&nbsp;&nbsp;&nbsp; if (st != OK) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return st;<br />
&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp; st = bar_ccc(&nbsp;&nbsp; );<br />
&nbsp;&nbsp;&nbsp;&nbsp; if (st != OK) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return st;<br />
&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp;return st;<br />
&nbsp;&nbsp;}</code></div></div><br />
<br />
A much cleaner method that I've been using for many years is as follows:<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>status&nbsp;&nbsp; foo(&nbsp;&nbsp;&nbsp;&nbsp;)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status st = OK;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; st = bar_aaa(&nbsp;&nbsp; ); ER_CHK(st);<br />
&nbsp;&nbsp;&nbsp;&nbsp; st = bar_bbb(&nbsp;&nbsp; ); ER_CHK(st);<br />
&nbsp;&nbsp;&nbsp;&nbsp; st = bar_ccc(&nbsp;&nbsp; ); ER_CHK(st);<br />
 <br />
ER_EXIT:<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;return st;<br />
<br />
}</code></div></div><br />
ER_CHK is a macro that is defined as follows: (simplified)<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define ER_CHK(st) if (st != OK) goto ER_EXIT; else ;</code></div></div><br />
<br />
However the use of the \"goto\" makes people shudder and point to appropriate section in MISRA - though shall not GOTO<br />
<br />
My question<br />
<br />
Is such a use of GOTO allowed ? <br />
Justification:<br />
<br />
  1. The GOTO is hidden in a macro and execution proceeds to a well defined point - this is as structured as the the jump commands behind the  f,while, switch - and yes - break statements. It is better than the break since the destination is well known<br />
<br />
2. The ER_CHK macro can be viewed as an extension of C<br />
<br />
3. It provides a single exit point. This is a major problem in the \"return\" method since if there is a resource to release it needs to be done before each return.<br />
<br />
4. The code is MUCH cleaner and robust<br />
<br />
5. The actual goto was outlawed because it's use lead to a mess - this  use <span style="font-style: italic;" class="mycode_i">prevents </span>the mess - and is more robust since the programmer does not deal with the \"ifs\" and \"returns\" - so can't introduce bugs by doing it wrongly ( \"=\" vs \"==\" bugs, no bug fogetting the \"return\" or doing cleanup before the return etc.)<br />
<br />
6. ER_CHK is actully defined as <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#define ER_CHK(st) if (st != OK)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {write_to_log(__LINE__, __FILE__); goto ER_EXIT; else ;</code></div></div><br />
So the log contains something like<br />
<br />
foo1.c (23) status = 3;<br />
foo2.c (125) status = 3;<br />
foo3.c (13) status = 3;<br />
<br />
Where a function in foo3.c on line 13 calls a function in foo2.c on line 125 etc.<br />
<br />
Even C++, Jave exceptions don't do that !!<br />
<br />
The attatched article provides more details and shows an implementation that is CPU and Memory efficient.<br />
<br />
Again - the quesion I'm asking is that the use of this mechanism illegal in MISRA ?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rationale for no goto, continue but allow break]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=46</link>
			<pubDate>Wed, 14 Sep 2005 14:55:31 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=141">niall</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=46</guid>
			<description><![CDATA[I know this should have been brought up before, but in reviewing MISRA-2 this passed me by.<br />
Being pedantic, why has the rule on break (14.6) been relaxed and not 14.5 (or 14.4)?<br />
A break in a loop is just a goto!<br />
I have no problem with it, it just smacks of inconsistency.]]></description>
			<content:encoded><![CDATA[I know this should have been brought up before, but in reviewing MISRA-2 this passed me by.<br />
Being pedantic, why has the rule on break (14.6) been relaxed and not 14.5 (or 14.4)?<br />
A break in a loop is just a goto!<br />
I have no problem with it, it just smacks of inconsistency.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Code Formatter / Beautifyer for 14.8 and 14.9 ?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=29</link>
			<pubDate>Wed, 04 May 2005 11:45:10 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=63">bmerkle</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=29</guid>
			<description><![CDATA[Hi there,<br />
<br />
is there any Code Formatter / Beautifyer that reformats C code according to the MISRA rules, e.g. MISRA2 Rule 14.9 or Rule 14.8 or MISRA1 Rule59 ?<br />
<br />
I know of artistic style (on sf) but unfortunately it has not the rule<br />
<br />
kind regards,<br />
Bernhard.]]></description>
			<content:encoded><![CDATA[Hi there,<br />
<br />
is there any Code Formatter / Beautifyer that reformats C code according to the MISRA rules, e.g. MISRA2 Rule 14.9 or Rule 14.8 or MISRA1 Rule59 ?<br />
<br />
I know of artistic style (on sf) but unfortunately it has not the rule<br />
<br />
kind regards,<br />
Bernhard.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[What about Macros for 14.3?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=19</link>
			<pubDate>Mon, 20 Dec 2004 18:59: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=19</guid>
			<description><![CDATA[Expanding upon the example in the MISRA 2004 Standard for 14.3:<br />
<br />
<br />
#define WHATABOUTTHIS   /* Um */ ;<br />
#define ORTHIS<br />
#define ANDTHISTOO      /* Well, I, uh... */<br />
<br />
void f()<br />
    {<br />
    ; /* OK */<br />
    /* Not OK */ ;<br />
    ;/* Not OK */<br />
    WHATABOUTTHIS<br />
    ORTHIS;<br />
    ANDTHISTOO;<br />
    }<br />
<br />
Which of the lines with macros, if any, violate the Rule?]]></description>
			<content:encoded><![CDATA[Expanding upon the example in the MISRA 2004 Standard for 14.3:<br />
<br />
<br />
#define WHATABOUTTHIS   /* Um */ ;<br />
#define ORTHIS<br />
#define ANDTHISTOO      /* Well, I, uh... */<br />
<br />
void f()<br />
    {<br />
    ; /* OK */<br />
    /* Not OK */ ;<br />
    ;/* Not OK */<br />
    WHATABOUTTHIS<br />
    ORTHIS;<br />
    ANDTHISTOO;<br />
    }<br />
<br />
Which of the lines with macros, if any, violate the Rule?]]></content:encoded>
		</item>
	</channel>
</rss>