[previous] MISRA C:2012  Rule-10.6:  (Required) [next] The value of a composite expression shall not be assigned to an object with wider essential type

Amplification:

This rule covers the assigning operations described in Rule 10.3.

Example Code:


#include "misra.h"
#include "m3cmex.h"

static int32_t   rule_1006a( void );
static uint32_t  rule_1006b( void );
static uint32_t  rule_1006c( void );
static uint32_t  rule_1006d( void );
static float64_t rule_1006e( void );

extern int16_t rule_1006( void )
{
    s32a = rule_1006a();
    u32a = rule_1006b();
    u32a = rule_1006c();
    u32a = rule_1006d();
    f64a = rule_1006e();

    return 1;
}

static int32_t rule_1006a( void )
{
    int32_t s16x = s8a + s8b;            /* 4490      */
    s16a = s8a + s8b;                    /* 4490      */
    s16f(s8a + s8b);                     /* 4490      */
    return(s8a + s8b);                   /* 4490      */
}

static uint32_t rule_1006b( void )
{
    uint32_t u16x = u8a + u8b;           /* 4491      */
    u16a = u8a + u8b;                    /* 4491      */
    u16f(u8a + u8b);                     /* 4491      */
    return(u8a + u8b);                   /* 4491      */
}

static uint32_t rule_1006c( void )
{
    uint32_t u16x = ~u8a;                /*      4499 */
    u16a = ~u8a;                         /*      4499 */
    u16f(~u8a);                          /*      4499 */
    return(~u8a);                        /*      4499 */
}

static uint32_t rule_1006d( void )
{
    uint32_t u16x = u8a << 2U;           /* 4491 4499 */
    u16a = u8a << 2U;                    /* 4491 4499 */
    u16f(u8a << 2U);                     /* 4491 4499 */
    return(u8a << 2U);                   /* 4491 4499 */
}

static float64_t rule_1006e( void )
{
    float64_t f64x = f32a + f32b;        /* 4492      */
    f64a = f32a + f32b;                  /* 4492      */
    ft64f(f32a + f32b);                  /* 4492      */
    return(f32a + f32b);                 /* 4492      */
}


QAC messages that encompass this guideline:

4490 A composite expression of 'essentially signed' type (%1s) is being converted to wider signed type, '%2s' on assignment.
4491 A composite expression of 'essentially unsigned' type (%1s) is being converted to wider unsigned type, '%2s' on assignment.
4492 A composite expression of 'essentially floating' type (%1s) is being converted to wider floating type, '%2s' on assignment.
4499 An expression which is the result of a ~ or << operation has been converted to a wider essential type on assignment.



(c) The Motor Industry Research Association, 2012
QA C Source Code Analyser 8.1.2
MISRA C:2012 Compliance Module 1.0
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents