what means about "Before preprocessing" in Rule[14.3]

6.14 Control Flow

Moderators: misra-c, david ward

Post Reply
linglingma
Posts: 1
Joined: Sun Jun 20, 2010 4:57 am
Company: Hirian

what means about "Before preprocessing" in Rule[14.3]

Post by linglingma » Wed Jun 23, 2010 1:33 pm

"Before preprocessing, a null statement shall only occur on a
line by itself; it may be followed by a comment provided that
the first character following the null statement is a white-space
character." in this rule,why "Before preprocessing"is used as a condition?
Thanks!

misra-c
Posts: 566
Joined: Thu Jan 05, 2006 1:11 pm

Re: what means about "Before preprocessing" in Rule[14.3]

Post by misra-c » Fri Jul 09, 2010 12:23 pm

Consider the following code fragment:

Code: Select all

void fn ( bool_t b )
{
   if ( b );   /* Non-compliant */
   {
      DO_SOMETHING;
   }
}
In the above DO_SOMETHING appears to be a (non-null) statement. However this depends on the value of the macro after pre-processing.

If the macro is defined as

Code: Select all

#define DO_SOMETHING
then the DO_SOMETHING line is actually a null statement which appears on a line by itself. In order to catch this, the source code before pre-processing must be considered. Pre-processing will simply remove the DO_SOMETHING token sequence.

Rule 14.3 is also designed to catch the accidental use of null statements by the unintentional insertion of a ';'. The non-compliant line is the example above shows how they can lead to unexpected results, as what appears to be the body of the if statement will always be executed.
---
Posted by and on behalf of
the MISRA C Working Group

gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

Re: what means about "Before preprocessing" in Rule[14.3]

Post by gs » Mon Dec 27, 2010 7:13 pm

However, according to http://www.misra-c2.com/forum/viewtopic.php?t=264, the line with the DO_SOMETHING macro usage is still non-compliant if the macro has the given definition, yes?

misra-c
Posts: 566
Joined: Thu Jan 05, 2006 1:11 pm

Re: what means about "Before preprocessing" in Rule[14.3]

Post by misra-c » Tue Jan 11, 2011 12:29 pm

Yes, it is non-compliant.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.14 Control Flow”