[previous] 0756 [next] [C] 'return' expression is not of compatible 'struct'/'union' type.
Constraint violations REFERENCE - ISO:C90-6.6.6.4 The return Statement - Semantics, ISO:C90-6.3.16.1 Simple Assignment - Constraints

This is a constraint error

The type of the return expression is not compatible with the specified return type of the function. The return type is a 'struct'/'union' type and the return expression must be of the same 'struct'/'union' type. For example:


/*PRQA S 750,759,2006,2213,2216,3120,3132,3210,3205,3227,3408,3447,3623,3624,3625 ++ */

struct ST1 { int si; char sbuf[10];};
struct ST2 { int si; char sbuf[10];};
union  UN1 { int ui; int uj;};

extern struct ST1 st1a;
extern struct ST2 st2a;
extern union  UN1 un1a;

extern int *pi;
extern int  gi;
extern char cbuf[10];

extern struct ST1 foo(int mode)
{
    if      (mode ==  0)
    {
        return(gi);                     /* Message 0756 */
    }
    else if (mode ==  1)
    {
        return(st2a);                   /* Message 0756 */
    }
    else if (mode ==  2)
    {
        return(un1a);                   /* Message 0756 */
    }
    else if (mode ==  3)
    {
        return(pi);                     /* Message 0756 */
    }
    else if (mode ==  4)
    {
        return(cbuf);                   /* Message 0756 */
    }
    else
    {
        return(st1a);                   /*              */
    }
}

See also:

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