MISRA Discussion Forums
Macros & 14.3 II - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.14 Control Flow (https://forum.misra.org.uk/forumdisplay.php?fid=46)
+---- Thread: Macros & 14.3 II (/showthread.php?tid=403)



Macros & 14.3 II - gs - 22-10-2007

Since, according to http://www.misra-c2.com/forum/viewtopic.php?t=264, the following code is not permitted:
Code:
#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 - 11-12-2007

Moving the semicolon to the macro definition removes the null statement issue.
Code:
#if debugging
#define ASSERT(x)    asserttest(x); /* not compliant with 19.4. */
#else
#define ASSERT(x)
#endif

void f(int *p)
{
    ASSERT(p != 0)
}