Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clarification for 6-5-1
#1
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.
Reply
#2
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
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)