Rules 13.4 Function call with float

6.13 Control Statement Expressions

Moderators: misra-c, david ward

Post Reply
Posts: 1
Joined: Thu May 30, 2013 8:53 am
Company: ISIT

Rules 13.4 Function call with float

Post by Bfr » Tue Jun 25, 2013 3:34 pm


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: Select all

int32_t i = 0;
float32_t float_var;


for (i = 0; i < float_to_int(float_var); ++i)
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.


Posts: 569
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rules 13.4 Function call with float

Post by misra-c » Thu Sep 12, 2013 9:23 am

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:


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
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.13 Control Statement Expressions”