[previous] 0562 [next] [C] Right operand of assignment points to a more heavily qualified type.
Constraint violations REFERENCE - ISO:C90-6.3.16.1 Simple Assignment - Constraints

This is a constraint error

An object of pointer type has been assigned the value of an expression which points to a more heavily qualified type.

The ISO:C Standard requires that the type pointed to by the pointer on the left of the assignment must have all the qualifiers of the type pointed to by the expression on the right. It is therefore not permissible to assign the value of an expression of type "const TYPE *" (pointer to const TYPE) or "volatile TYPE *" (pointer to volatile TYPE) to an object of type "TYPE *" (pointer to TYPE); to do so would permit the type qualification restrictions to be violated.

On the other hand, it is perfectly legitimate to initialize an object of type "const TYPE *" or "volatile TYPE *" or even "const volatile TYPE *" with an expression of type "TYPE *".

For example:


/*PRQA S 3198,3199,3203,3205,3210,3408,3447,3602 ++ */
extern int                *gpi;
extern const int          *gpci;
extern volatile int       *gpvi;
extern const volatile int *gpcvi;

void test(void)
{
    int                *xpi;
    const int          *xpci;
    volatile int       *xpvi;
    const volatile int *xpcvi;

    xpi = gpi;                /*              */
    xpi = gpci;               /* Message 0562 */
    xpi = gpvi;               /* Message 0562 */
    xpi = gpcvi;              /* Message 0562 */

    xpci = gpi;               /*              */
    xpci = gpci;              /*              */
    xpci = gpvi;              /* Message 0562 */
    xpci = gpcvi;             /* Message 0562 */

    xpvi = gpi;               /*              */
    xpvi = gpci;              /* Message 0562 */
    xpvi = gpvi;              /*              */
    xpvi = gpcvi;             /* Message 0562 */

    xpcvi = gpi;              /*              */
    xpcvi = gpci;             /*              */
    xpcvi = gpvi;             /*              */
    xpcvi = gpcvi;            /*              */
}


MISRA C:2012 Rules applicable to message 0562:

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