MISRA Discussion Forums

Full Version: Rule 18.4 using -- operator for pointers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear

Rule 18.4 mentions +, -, += and -= operators and also ++ operator (both post and pre fix?). -- operator is not mentioned. How to deal with it?

Regards
Rule 18.4 prohibits the use of "+, -, +=, -=" operators on expressions with a pointer type. All other operators that are legal C do not violate this rule. This includes ++ and --, both prefix and postfix.

The rationale mentions the ++ operator as an example of a valid operator that is not restricted by this rule. It was not intended that the rationale should list all valid operators.

As a general point, it should be remembered that the rationale section is not normative. Only the guideline headline and amplification (where present) are intended to specify which operators the guideline applies to.