Rule 19.4

6.19 Preprocessing Directives

Moderators: misra-c, david ward

Locked
aravind
Posts: 2
Joined: Tue Apr 12, 2005 7:14 pm
Location: USA

Rule 19.4

Post by aravind » Fri Mar 31, 2006 8:20 pm

Is the usage of ternary operator (? :) inside a C macro violation of rule 19.4. For e.g. the following function-like macro

#define abs(x) (((x) >= 0) ? (x) : -(x))

According to Rule 19.4 - C macros shall only expand to a braced initialiser, a constant, a parenthesized expression, a type qualifier, a storage class specifier or a do-while construct.

Does the above function-like macro conform to rule 19.4?
--------------------------------------------------------
Aravind Pillarisetti
The MathWorks
--------------------------------------------------------

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

Post by misra-c » Thu Apr 27, 2006 11:47 am

The macro containing the ternary operator expands to a parenthesized expression and therefore is allowed.
---
Posted by and on behalf of
the MISRA C Working Group

Locked

Return to “6.19 Preprocessing Directives”