MISRA Discussion Forums
Clarification for 6-5-1 - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19)
+---- Forum: 6.5 Expressions (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=134)
+---- Thread: Clarification for 6-5-1 (/showthread.php?tid=608)



Clarification for 6-5-1 - pkruk - 12-01-2009

Quote:A for loop shall contain a single loop-counter which shall not have floating type.

Is following code compliant?

Code:
void foo() {
    const char * x = "Foo";
    for (const char * ptr = x; *ptr; ++ptr) { // Compliant?
        // ...
    }
}

In my opinion the loop-control-variable (ptr) is not "an operand to a relational operator in condition" (the variable pointed to by the ptr is the operand) so it does not meet conditions for a loop-counter.


Re: Clarification for 6-5-1 - misra cpp - 11-10-2016

The example provided does not have a loop counter - by clause b of the definition that it is "an operand to a relational operator in condition;" ptr is not the operand to the (implied) != 0, *ptr is