/* >>>------------------------------------------------------------ * * File: rule_10.2.c, Module: M2CM-3.2-QAC-8.1.2 * * RULE 10.2 (Required): * The value of an expression of floating type shall not be * implicitly converted to a different type if: * a) it is not a conversion to a wider floating type, or * b) the expression is complex, or * c) the expression is a function argument, or * d) the expression is a return expression * * Implemented by messages: * 1264 A suffixed floating constant is being converted to a * different floating type on assignment. * * 1265 An unsuffixed floating constant is being converted to a * different floating type on assignment. * * 1266 A floating constant is being converted to integral type * on assignment. * * 1880 The operands of this relational operator are expressions * of different 'essential type' categories (%1s and %2s). * * 1881 The operands of this equality operator are expressions * of different 'essential type' categories (%1s and %2s). * * 1882 The 2nd and 3rd operands of this conditional operator * are expressions of different 'essential type' categories * (%1s and %2s). * * 1892 A composite expression of 'essentially floating' type * (%1s) is being implicitly converted to a wider floating * type, '%2s'. * * 1893 The 2nd and 3rd operands of this conditional operator * are both 'essentially signed' ('%1s' and '%2s') but one * is a composite expression of a narrower type than the * other. * * 1894 The 2nd and 3rd operands of this conditional operator * are both 'essentially unsigned' ('%1s' and '%2s') but * one is a composite expression of a narrower type than * the other. * * 1895 The 2nd and 3rd operands of this conditional operator * are both 'essentially floating' ('%1s' and '%2s') but * one is a composite expression of a narrower type than * the other. * * 4450 An expression of 'essentially floating' type (%1s) is * being converted to Boolean type, '%2s' on assignment. * * 4452 An expression of 'essentially floating' type (%1s) is * being converted to enum type, '%2s' on assignment. * * 4453 An expression of 'essentially floating' type (%1s) is * being converted to signed type, '%2s' on assignment. * * 4454 An expression of 'essentially floating' type (%1s) is * being converted to unsigned type, '%2s' on assignment. * * 4462 A non-constant expression of 'essentially floating' type * (%1s) is being converted to narrower floating type, * '%2s' on assignment. * * 4465 A constant expression of 'essentially floating' type * (%1s) is being converted to narrower floating type, * '%2s' on assignment. * * 4472 A non-constant expression of 'essentially floating' type * (%1s) is being passed to a function parameter of wider * floating type, '%2s'. * * 4482 A non-constant expression of 'essentially floating' type * (%1s) is being returned from a function defined with a * wider floating return type, '%2s'. * * 4492 A composite expression of 'essentially floating' type * (%1s) is being converted to wider floating type, '%2s' * on assignment. * * <<<------------------------------------------------------------ */ /* PRQA S 2889,2981,2982,2983,3112,3203,3334,3408 ++ */ #include "misra.h" #include "m2cmex.h" static F32 test_1002a( void ); static F64 test_1002b( void ); extern S16 test_1002( void ) { /***************** Assignment ******************/ f64a = f32a; f64a = 2.34; f64a = 5.3F; f64a = 5.3; f64a = 5.3L; f128a = 5.3L; f32a = (s32a > 0) ? f32a : f32b; f32a = test_1002a(); f64a = test_1002b(); s16a = f32a; /* MISRA Violation */ s16a = 1.23F; /* MISRA Violation */ u32a = f32b; /* MISRA Violation */ u32a = 2.34F; /* MISRA Violation */ f32a = 5.3; /* MISRA Violation */ f32a = 5.3L; /* MISRA Violation */ bla = f64a; /* MISRA Violation */ f64a = f32a + f32b; /* MISRA Violation */ f32a = (s32a > 0) ? f64a : f64b; /* MISRA Violation */ f32a = (s32a > 0) ? 1.23 : 2.34; /* MISRA Violation */ /***************** Balancing ******************/ f64a + f32b; f64a + (f32a * f32b); /* MISRA Violation */ /***************** Function arguments ******************/ use_s16(f32a); /* MISRA Violation */ use_f32(f64a); /* MISRA Violation */ use_f64(f32a); /* MISRA Violation */ use_f64(f32a + f32b); /* MISRA Violation */ return 1; } /***************** Function return expressions ******************/ static F32 test_1002a ( void ) { switch (s8a) { case 1: return(f64a); /* MISRA Violation */ case 2: return ( 1.23 ); /* MISRA Violation */ default: return 0.0F; } } static F64 test_1002b ( void ) { switch (s8a) { case 1: return ( f128a ); /* MISRA Violation */ case 2: return ( f32a + f32b ); /* MISRA Violation */ default: return ( 1.23F ); /* MISRA Violation */ } }