[previous] 0484 [next] [C] A pointer to an object of unknown size cannot be the operand of a subtraction operator.
Constraint violations REFERENCE - ISO:C90-6.3.6 Additive Operators - Constraints

This is a constraint error

When performing any kind of pointer arithmetic, it is always necessary to know the size of the object being addressed. For example, when subtracting "1" from a pointer, the value of the pointer is not decremented by 1 byte but by the size (in bytes) of the type being addressed. For this reason, a pointer to an incomplete type cannot be the operand of a subtraction operator.

For example:


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

extern struct ST *sa;
extern struct ST *sb;

void foo(int n, void *pv)
{
    pv = pv - n;    /* Message 0484 */
    sa = sb - 2;    /* Message 0484 */
}


MISRA C:2012 Rules applicable to message 0484:

Rule-1.1  (Required) The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limits


See also:

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