MISRA Discussion Forums

Full Version: Clarification for 6-5-1
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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