Macros & 14.3 II

6.14 Control Flow

Moderators: misra-c, david ward

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

Macros & 14.3 II

Post by gs » Mon Oct 22, 2007 3:51 pm

Since, according to http://www.misra-c2.com/forum/viewtopic.php?t=264, the following code is not permitted:

Code: Select all

#if debugging
#define ASSERT(x)    asserttest(x)
#else
#define ASSERT(x)
#endif

void f(int *p)
    {
    ASSERT(p != 0);
    }
How would one make code well formed with respect to assertion macros?

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

Post by misra-c » Tue Dec 11, 2007 12:14 pm

Moving the semicolon to the macro definition removes the null statement issue.

Code: Select all

#if debugging 
#define ASSERT(x)    asserttest(x); /* not compliant with 19.4. */
#else 
#define ASSERT(x) 
#endif 

void f(int *p) 
{ 
    ASSERT(p != 0) 
}
---
Posted by and on behalf of
the MISRA C Working Group

Locked

Return to “6.14 Control Flow”