Examples in 6.5.3 do not match definition of a loop-counter

Moderators: david ward, misra cpp

drstaiger
Posts: 2
Joined: Thu Oct 13, 2011 3:04 am
Company: Axivion GmbH

Examples in 6.5.3 do not match definition of a loop-counter

Postby drstaiger » Mon Oct 14, 2013 11:16 am


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

Re: Examples in 6.5.3 do not match definition of a loop-coun

Postby misra cpp » Mon Dec 08, 2014 12:08 pm

You are correct to say that the non-compliant loops do not have a loop counter to modify.

The two loops concerned should have ++x added as the third expression to the loop. This correction will be included in a technical update to the document.

Thank you for bringing this to our attention.
Posted by and on behalf of
the MISRA C++ Working Group

paetzold
Posts: 4
Joined: Thu Jan 26, 2017 2:08 pm
Company: Fresenius Medical Care Deutschland GmbH

Re: Examples in 6.5.3 do not match definition of a loop-counter

Postby paetzold » Fri Feb 03, 2017 8:08 am


mishak
Posts: 10
Joined: Thu Jun 21, 2007 3:58 pm

Re: Examples in 6.5.3 do not match definition of a loop-counter

Postby mishak » Fri Feb 03, 2017 10:20 am

The official response seems reasonable to me - it has been given to us by the team that wrote the rule and they are simply clarifying the intent of the rule.

Think about it from the point of view of trying to check the code (with a tool). A tool will have to look for patterns within the code to try and identifiy when a loop is non-compliant. The C++ Standard does not define "loop counters". It may be "obvious" to a programmer what a loop counter is, but a formal specification is needed if tools are going to have a consistent interpretation of what is (or is not) a loop counter. The introductory text before 6-5-1 provides such a specification. The examples in 6-5-3 do not meet the criteria given and therefore do not have loop counters, even if the second example does have something "like a loop counter".

You say that "... only the programmer wanted some trickier modifiation and put it somewhere else". That is a good point and it highlights why the rules exist - they restrict the complexity that is acceptable for a loop without the use of a deviation.

paetzold
Posts: 4
Joined: Thu Jan 26, 2017 2:08 pm
Company: Fresenius Medical Care Deutschland GmbH

Re: Examples in 6.5.3 do not match definition of a loop-counter

Postby paetzold » Fri Feb 03, 2017 11:23 am


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

Re: Examples in 6.5.3 do not match definition of a loop-counter

Postby misra cpp » Mon Jul 10, 2017 11:16 am

You are correct. "++x" should be added as the third expression in these loops.
Posted by and on behalf of
the MISRA C++ Working Group


Return to “6.6 Statements (C++)”

Who is online

Users browsing this forum: No registered users and 5 guests