[previous] 1266 [next] A floating constant is being converted to integral type on assignment.
Arithmetic type - Assignment

This message is issued whenever a floating constant undergoes an assigning conversion to integral type.

For example:


/*PRQA S 1-9999 ++*/
/*PRQA S 1266, 1269 --*/

extern int sia;

void foo (int a);

int f1266 (void)
{
  sia   = 5.0F;             /* 1266 */
  sia   = (int)5.0F;        /* 1269 */

  sia   = 5.0;              /* 1266 */
  sia   = (int)5.0;         /* 1269 */

  sia   = 5.0L;             /* 1266 */
  sia   = (int)5.0L;        /* 1269 */
  
  foo (5.0);                /* 1266 */

  return 5.0;               /* 1266 */
}


MISRA-C:2004 Rules applicable to message 1266:

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


See also:

QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents