[previous] 0758 [next] [C] 'return' expression is not of compatible pointer 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 pointer type and the return expression must point to a compatible (possibly less qualified) type.

For example:


/*PRQA S 750,759,2006,2213,2216,3120,3132,3227,3408,3447,3625 ++ */
struct ST1 { int si; char sbuf[10];};
union  UN1 { int ui; int uj;};

extern struct ST1 st1a;
extern union  UN1 un1a;

extern int            var;
extern int           *pi;
extern int          **ppi;
extern char          *pc;
extern unsigned char *puc;

char * func(int mode)
{
    if      (mode ==  0)
    {
        return(var);                   /* Message 0758 */
    }
    else if (mode == 1)
    {
        return(st1a);                  /* Message 0758 */
    }
    else if (mode == 2)
    {
        return(un1a);                  /* Message 0758 */
    }
    else if (mode == 3)
    {
        return(ppi);                   /* Message 0758 */
    }
    else if (mode == 4)
    {
        return(pi);                    /* Message 0758 */
    }
    else if (mode == 5)
    {
        return(pc);                    /*              */
    }
    else
    {
        return(puc);                   /* Message 0758 */
    }
}

Note that according to ISO:C Standard 'char' and 'unsigned char' (or 'signed char') are distinct types, even though 'char' may be implemented as 'unsigned char' (or 'signed char'). For this reason message 0758 is generated for the last return statement in the example above. If your compiler incorrectly allows such a conversion, you can use QA·C option -foldplainchar (compiler personality) to mimic this behaviour.

See also:

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