[previous] 1421 [next] An enum object is being passed as argument to a function parameter of a different enum type.
Arithmetic type - Enum types REFERENCE - ISO:C90-6.5.2.2 Enumeration Specifiers

An object of enum type is being passed as a function argument. However, the corresponding parameter in the function definition is of a different enum type. This is permitted in the C language but is it really intended ? It could result in an enum object containing a value which is not a valid member of the enumeration.

For example:


/*PRQA S 1277,2006,2017,2201,2203,3198,3227,3408,3447,3448,3602 ++*/

typedef enum tree
{
    fir   ,
    cedar ,
    maple ,
    pine   } TREE;

typedef enum color
{
    red   ,
    white ,
    black ,
    violet } COLOUR;

extern void func1(TREE trp);

extern TREE   tra;
extern COLOUR col;

extern TREE foo(void)
{
   func1(col);                     /* Message 1421 */
   tra = col;                      /* Message 1422 */
   return(col);                    /* Message 1423 */
}

See also:

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