Posts: 117
Threads: 25
Joined: Apr 2016
Reputation:
0
The code example also violates Directive 4.6 and Rule 1.2.
The problem with language extensions such as _Complex is, that they have no essential type in the MISRA document.
But i would imagine that f=fc is a certain violation, because the imaginary part seems to be sliced.
And d=fc and fc=d because they are essentially different.
<t></t>
Posts: 632
Threads: 18
Joined: Jan 2006
Reputation:
1
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
Posts: 632
Threads: 18
Joined: Jan 2006
Reputation:
1
Support for _Complex was added my MISRA C:2012 Amendment 3, and incorporated into MISRA C:2023
Posted by and on behalf of the MISRA C Working Group