Rules 13.4 Function call with float - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4) +--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17) +---- Forum: 6.13 Control Statement Expressions (https://forum.misra.org.uk/forumdisplay.php?fid=40) +---- Thread: Rules 13.4 Function call with float (/showthread.php?tid=965) |
Rules 13.4 Function call with float - Bfr - 25-06-2013 Hello, As the rule 13.4 says : The controlling expression of a for statement shall not contain any objects of floating type. But what about a function call with a float as parameter (example below) ? I am asking this in order to implement a MISRA rule checker. Code: int32_t i = 0; It seems correct to me since the float is not really use in the controlling expression. But the rules says any objects and that confuse me a little. Thanks, Ben Re: Rules 13.4 Function call with float - misra-c - 12-09-2013 Using a floating point object to count or compare loop iterations is not recommended. For some values of the loop limits and increment, the accumulation of rounding errors could result in a number of iterations that differs from the expected number. There are contexts in which use of floating point objects in a controlling expression might not cause any issues (including the example you cite). However a strict interpretation of MISRA-C:2004 does not permit any such uses. See also: http://misra.org.uk/forum/viewtopic.php?f=69&t=873 --- For MISRA C:2012 this has been clarified in Rule 14.1 and Rule 14.2 - this would allow your example to be compliant, provided that float_to_int(float_var) was invarient |