[previous] 0450 [next] [C] An expression of array type cannot be cast.
Constraint violations REFERENCE - ISO:C90-6.3.4 Cast Operators - Constraints, ISO:C90-6.2.2.1 Lvalues and Function Designators

This is a constraint error

An expression of array type is the operand of a cast.

This is not permitted. The operand of a cast must always be of scalar type.

An expression of array type is unusual because an lvalue of array type is always converted to an expression that has type "pointer to type". Message 450 is therefore only generated when an expression of array type is not an lvalue.

For example:


/*PRQA S 310,2213,3132,3198,3199,3203,3205,3408,3447,3625,3631 ++*/

struct ST { int ai[3]; };

extern struct ST sf(void);
extern struct ST sta;
extern int       ibuf[10];

void foo(void)
{
    char *pc;

    pc = (char *)ibuf;              /* OK - ibuf decays to type pointer to int      */
    pc = (char *)(sta.ai);          /* OK - sta.ai decays to type pointer to int    */
    pc = (char *)(sf().ai);         /* Message 0450 and also 0481                   */
    pc = (char *)sta;               /* Message 0481 - sta is not of scalar type     */
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents