[previous] 3892 [next] The result of this cast is implicitly converted to another type.
Arithmetic type - Operations

The result of this cast is immediately subject to an implicit conversion to a different type. Is this intended ?

Casts may be used for a number of different purposes:
  1. To document or validate a type conversion which would otherwise be performed implicitly and possibly unnoticed.
  2. To ensure type consistency in a context where code might otherwise be subject to implementation-defined behaviour.
  3. To force a type change in order to change the semantic behaviour of an expression.

A cast is often used as an alternative to modulo arithmetic or bit-masking in unsigned arithmetic. In this context, it is entirely possible that the result of the cast may immediately be subject to an implicit conversion to a different type.

For example:


/*PRQA S 3198,3199,3203,3227,3408 ++*/

#define MASK 0xA5A5FEFEu

extern void foo(unsigned int x)
{
    unsigned int r;

    r = (unsigned char)x;                       /* Message 3892 */

    r = (unsigned char)MASK;                    /* Message 3892 */
}

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