/* >>>------------------------------------------------------------ * * File: rule_12.1.c, Module: M2CM-3.2-QAC-8.1.2 * * RULE 12.1 (Advisory): * Limited dependence should be placed on C's operator precedence * rules in expressions. * * Implemented by messages: * 3389 Extra parentheses recommended to clarify the ordering of * a % operator and another arithmetic operator (* / % + * -). * * 3391 Extra parentheses recommended. A conditional operation * is the operand of another conditional operator. * * 3392 Extra parentheses recommended. A shift, relational or * equality operation is the operand of a second identical * operator. * * 3393 Extra parentheses recommended. An arithmetic operation * (* / + -) is the operand of a different operator with * the same precedence. * * 3394 Extra parentheses recommended. A shift, relational or * equality operation is the operand of a different * operator with the same precedence. * * 3395 Extra parentheses recommended. A * or / operation is the * operand of a + or - operator. * * 3396 Extra parentheses recommended. A binary operation is the * operand of a conditional operator. * * 3397 Extra parentheses recommended. A binary operation is the * operand of a binary operator with different precedence. * * <<<------------------------------------------------------------ */ /* PRQA S 2982-2986,2995,2996,3203,3408,3447 ++ */ #include "misra.h" #include "m2cmex.h" extern S16 test_1201( void ) { U16 ua = u16a; U16 ub = u16a; U16 uc = u16a; U16 ud = u16a; S16 a = s16a; S16 b = s16a; S16 c = s16a; S16 d = s16a; const S16 buf[ 10 ] = { 0 }; const S16 tbuf[ 2 ][ 2 ] = { { 0, 1 }, { 1, 2 } }; const S16 *pi = &buf[ 0 ]; const S16 * const *ppi = π S16 ( * const f[ 1000 ] )( S16 sx ) = { 0 }; S16 r; U16 ur; struct st { S16 x; S16 y; const struct st *pst; }; struct st sv1; const struct st *s = &sv1; const struct st sv2 = { 0, 1, ( const struct st * )0 }; sv1.pst = &sv2; r = a + b + c; r = a - b - c; r = a * b * c; r = a / b / c; r = buf[ b * c ] + d; r = buf[ a ] * b * c; r = s->pst->x; ur = ua & ub & uc; ur = ua | ub | uc; ur = ua ^ ub ^ uc; bla = ( a + b ) > 200; r = tbuf[ a * b ][ c ] - d; ur = (U16)~ua; ur = (U16)~ua & ub; pi = *ppi; r = a + *pi; r = *pi + a; r = **ppi; r = a + **ppi; r = **ppi + a; r = *pi + **ppi; ur = (U16)~ua + ub; r = a * *pi; pi = &buf[ 3 ]; r = a + b++; r = *++pi; r = a + b - c; /* MISRA Violation */ r = a + b - c + d; /* MISRA Violation */ r = a / b * c; /* MISRA Violation */ ur = ua >> ub >> uc; /* MISRA Violation */ ur = ua << ub << uc; /* MISRA Violation */ bla = a + b > 200; /* MISRA Violation */ ur = ua + ub & uc; /* MISRA Violation */ ur = ua + ub >> 2; /* MISRA Violation */ bla = ua * ub > 200U; /* MISRA Violation */ ur = ua * ub & uc; /* MISRA Violation */ ur = ua * ub >> 2; /* MISRA Violation */ bla = a > b + 1; /* MISRA Violation */ ur = ua >> ub >> uc; /* MISRA Violation */ ur = ua & ub | uc; /* MISRA Violation */ r = a + b * c; /* MISRA Violation */ r = a + ( b - c ) * d; /* MISRA Violation */ r = buf[ a ] * b + c; /* MISRA Violation */ ur = ua & ub * uc + ud; /* MISRA Violation */ r = b != d ? c : a != 0 ? b : d; /* MISRA Violation */ r = a * ( f[ a ] )( c + 2 ) + d; /* MISRA Violation */ /* THE RULES ARE A BIT DIFFERENT FOR && and || OPERATORS */ bla = (a < b) && (b < c) && (c < d); bla = (a < b) || (b < c) || (c < d); bla = ( a > 200 ) && (c < 400); bla = (a < b) && (b < c) || (c < d); /* MISRA Violation */ bla = (a < b) || (b < c) && (c < d); /* MISRA Violation */ bla = a > 200 && (b > c); /* MISRA Violation */ bla = !(a > b) && (b != c); /* MISRA Violation */ bla = !(a > b) || (c == d); /* MISRA Violation */ return 0; }