[previous] MISRA C:2012  Rule-18.2:  (Required) [next] Subtraction between pointers shall only be applied to pointers that address elements of the same array

Example Code:


#pragma PRQA_MESSAGES_OFF 2982,2983

#include "misra.h"
#include "m3cmex.h"

extern int16_t rule_1802( void )
{
    int16_t   buf1[10];
    int16_t   buf2[10];
    int16_t * p1;
    int16_t * p2;
    int16_t * p3;
    int32_t   dx;

    p1 = buf1;
    p2 = buf2;
    dx = p2 - p1;                                               /* 2771 0488 */

    p3 = buf1;
    if (s16a > 0)
    {
        p3 = buf2;
    }

    dx = p3 - p1;                                               /* 2772 0488 */

    return 1;
}



QAC messages that encompass this guideline:

2771 Definite: These pointers address different objects.
2772 Apparent: These pointers address different objects.


Related rules:

Rule-18.3 The relational operators >, >=, < and <= shall not be applied to objects of pointer type except where they point into the same object



(c) The Motor Industry Research Association, 2012
QA C Source Code Analyser 8.1.2
MISRA C:2012 Compliance Module 1.0
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents