/* >>>------------------------------------------------------------ * * File: rule_17.2.c, Module: M2CM-3.2-QAC-8.1.2 * * RULE 17.2 (Required): * Pointer subtraction shall only be applied to pointers that * address elements of the same array. * * Implemented by messages: * 2771 Definite: These pointers address different objects. * * 2772 Apparent: These pointers address different objects. * * <<<------------------------------------------------------------ */ /* PRQA S 2982, 2984 ++ */ #include "misra.h" #include "m2cmex.h" extern S16 test_1702( void ) { PC arr[] = "text"; PC *ch = arr; PC *last = &arr[ 3 ]; S32 a = 1; S32 *p_a1 = &a; S32 *p_a2 = &a; struct { S32 xx; S32 yy; } b1, b2; S32 *p_b1; S32 *p_b2; S16 nch; nch = ( last - ch ) + 1; nch = p_a2 - p_a1; p_b1 = &b1.xx; p_b2 = &b1.yy; nch = p_b2 - p_b1; /* MISRA Violation */ p_b1 = &b1.xx; p_b2 = &b2.yy; nch = p_b2 - p_b1; /* MISRA Violation */ return nch; }