[previous] 2771 [next] Definite: These pointers address different objects.
Pointers

A definite condition has been detected. An operation is being performed to compare or subtract the value of two pointers which address different objects.

Behaviour is undefined if an attempt is made to subtract pointers which do not address elements of the same array or to compare (with a relational operator) pointers which do not point to the same struct, union or array.

For example:


/*PRQA S 488,490,2017,2983,2991,2995,3132,3203,3355,3358,3408,3447 ++*/

extern int buf1[10];
extern int buf2[10];

extern void f2771(void)
{
    int * p1;
    int * p2;
    long  d;
    
    p1 = buf1;
    p2 = buf2;
    d = p2 - p1;      /* 2771 */
    
    if (p2 > p1)      /* 2771 */
    {
    }
}


MISRA-C:2004 Rules applicable to message 2771:

Rule  17.2  (Required) Pointer subtraction shall only be applied to pointers that address elements of the same array.
Rule  17.3  (Required) >, >=, <, <= shall not be applied to pointer types except where they point to the same array.


See also:

QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents