Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 10.3, conversion from complex types to real floating types
#6
When a value of complex floating type is converted to a real floating type, the imaginary part is discarded (C99 6.3.17(2)) and the real part is converted according to the normal C conversion rules. The normal MISRA C:2012 guidelines apply to the conversion on the real part.
Code:
d = fc;  // permitted float -> double conversion
  f = fc;  // permitted no conversion required as float to float
However the following would violate rule 10.3
Code:
double _Complex dc;
  f = dc;  // violates rule 10.3 since real part undergoes narrowing conversion.

When a value of real floating type is converted to a complex floating type, the imaginary part is given the value of 0 (C99 6.3.17(1)) and the real part is converted according to the normal C conversion rules. The normal MISRA C:2012 guidelines apply to the conversion on the real part.
Code:
fc = d;  // violates rule 10.3 since real part undergoes narrowing conversion.
   fc = f;  // permitted no conversion required as float to float
More discussion on MISRA C:2012 handling of complex types can be found at http://www.misra.org.uk/forum/viewtopic.php?t=1273
Posted by and on behalf of the MISRA C Working Group


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)