MISRA Discussion Forums

Full Version: Rule 19.4
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
The macro containing the ternary operator expands to a parenthesized expression and therefore is allowed.