[previous] 3911 [next] unsigned char value returned from char %s().
Arithmetic type - Implicit conversions

An expression of type unsigned char is being implicitly converted to type char. Is this intended ? This operation is dangerous unless it can be confirmed that char is implemented as an unsigned type.

Implicit type conversions of this nature can occur in the context of:

In the C language there exist 3 distinct char types:

It is recommended that signed char and unsigned char should be used for "numeric" data and plain char should be used for "character" data. Numeric data can be stored in type char but the range of values will be implementation-defined because the type is sometimes implemented as a signed type and sometimes as an unsigned type. Likewise, character data can be stored in type signed char or type unsigned char, but it is more sensible to use type char.

For example:


/*PRQA S 2017,3197,3199,3203,3227,3408,3447,3602,3625 ++*/


extern void ef(char p);

extern char foo(unsigned char v)
{
    char a = v;                 /* Message 3711 */

    a = v;                      /* Message 3711 */

    ef(v);                      /* Message 3711 */

    return v;                   /* Message 3911 */
}

See also:

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