What about Macros for 14.3?

6.14 Control Flow

Moderators: misra-c, david ward

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

What about Macros for 14.3?

Post by gs » Mon Dec 20, 2004 6:59 pm

Expanding upon the example in the MISRA 2004 Standard for 14.3:


#define WHATABOUTTHIS /* Um */ ;
#define ORTHIS
#define ANDTHISTOO /* Well, I, uh... */

void f()
{
; /* OK */
/* Not OK */ ;
;/* Not OK */
WHATABOUTTHIS
ORTHIS;
ANDTHISTOO;
}

Which of the lines with macros, if any, violate the Rule?

Gavin McCall
Posts: 72
Joined: Mon Sep 13, 2004 9:24 am

Post by Gavin McCall » Fri Sep 09, 2005 3:35 pm

Code: Select all

#define M1 ;
This macro breaks rule 19.4. Macro expanding to Null statement is not allowed.

Code: Select all

#define M2
#define M3 /* comment */
This macro expands to no body, and is therefore not prohibited by 19.4.

A comment in a macro definition is removed by the pre-processor. Rule 14.3 applied before
Pre-processing. Treatment of M2 and M3 is identical.

Code: Select all

M1
Since definition of M1 macro was invalid, its use is already a violation.

Code: Select all

M2;
M3;
After pre-processing, these are both Null statements. Before pre-processing, there are characters before the Null statement. This is not allowed by 14.3.
Gavin McCall
Personal view only.

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

Post by misra-c » Tue Aug 29, 2006 4:50 pm

Code: Select all

#define M1 ;


This macro breaks rule 19.4. Macro expanding to Null statement is not allowed.

Code: Select all

#define M2 
#define M3 /* comment */


This macro expands to no body, and is therefore not prohibited by 19.4.

A comment in a macro definition is removed by the pre-processor. Rule 14.3 applied before
Pre-processing. Treatment of M2 and M3 is identical.

Code: Select all

M1


Since definition of M1 macro was invalid, its use is already a violation.

Code: Select all

M2; 
M3; 
After pre-processing, these are both Null statements. Before pre-processing, there are characters before the Null statement. This is not allowed by 14.3.
Re-posted under offical user name only.
---
Posted by and on behalf of
the MISRA C Working Group

Locked

Return to “6.14 Control Flow”