Rule 19.7 - Function-like macro

6.19 Preprocessing Directives

Moderators: misra-c, david ward

Post Reply
patopat
Posts: 1
Joined: Tue Nov 08, 2011 1:50 pm
Company: Michelin R&D

Rule 19.7 - Function-like macro

Post by patopat » Tue Nov 08, 2011 4:05 pm

I have a violation of MISRA 2004 Advisory Rule 19.7, Function-like macro defined: 'CONV'

#define F_MIN (-0.5)
#define F_MAX (0.5)
#define CONV(x) ((int32_t) ((x) < F_MAX ? ((x) >= F_MIN ? (x)*0x80000000U : 0xFFFF8000U) : 0x7fff0000U))

int32_t myVariable = CONV(0.25); /* the preprocessor replace macro with the value 0x20000000 */

How I declare the macro CONV(), which is not a function but really a preprocessor task, to be compliant to MISRA ?

BR,

Pat

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

Re: Rule 19.7 - Function-like macro

Post by misra-c » Tue Nov 15, 2011 8:37 pm

Rule 19.7 is only intended to apply in situations where a function call would be permitted.

As an example, a function call is not permitted in a constant-expression. Therefore Rule 19.7 does not apply to the initialisers for objects that have static storage duration, e.g.

Code: Select all

static int32 myVariable = CONV(0.25);   /* Rule 19.7 compliant - function not permitted here */
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.19 Preprocessing Directives”