[previous] 0486 [next] [C] Only integral expressions and compatible pointers may be subtracted from pointers.
Constraint violations REFERENCE - ISO:C90-6.3.6 Additive Operators - Constraints

This is a constraint error

If the left hand operand of a subtraction operator is a pointer, the other operand must either be a pointer to a compatible object type or else an expression of integral type.

For example:


/*PRQA S 488,510,3120,3199,3203,3227,3408,3447,3681 ++*/

extern int * pi;
extern int * pj;

void foo(float dec)
{
    long sx;

    pi = pj - 2;                  /* OK - subtracting an integer value     */
    sx = pi - pj;                 /* OK - subtracting a compatible pointer */
    pi = pi - dec;                /* Message 0486                          */
}


MISRA-C:2004 Rules applicable to message 0486:

Rule  1.1  (Required) All code shall conform to ISO/IEC 9899:1990 C programming language, ISO 9899, amended and corrected by ISO/IEC 9899/COR1:1995, ISO/IEC 9899/AMD1:1995, and ISO/IEC 9899/COR2: 1996192


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