Rule 19.4 - 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.19 Preprocessing Directives (https://forum.misra.org.uk/forumdisplay.php?fid=43) +---- Thread: Rule 19.4 (/showthread.php?tid=237) |
Rule 19.4 - aravind - 31-03-2006 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? - misra-c - 27-04-2006 The macro containing the ternary operator expands to a parenthesized expression and therefore is allowed. |