Clarification for 6-5-1

Moderators: david ward, misra cpp

Post Reply
Posts: 20
Joined: Fri Jul 27, 2007 3:25 pm

Clarification for 6-5-1

Post by pkruk » Mon Jan 12, 2009 10:21 am

A for loop shall contain a single loop-counter which shall not have floating type.
Is following code compliant?

Code: Select all

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.

misra cpp
Posts: 151
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: Clarification for 6-5-1

Post by misra cpp » Tue Oct 11, 2016 10:50 am

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

Post Reply

Return to “6.5 Expressions (C++)”