Page 1 of 1

6.5 - variable kinds suitable for use as loop counter

Posted: Thu Feb 16, 2017 6:48 pm
by grunwald
Which of the following is a 'variable' and thus suitable for use as loop counter (and subject to the restrictions on loop-control-variables)?
  • local variable
  • static/global variable
  • class member variable
  • function parameter

    Code: Select all

    void f(int x) { for (; x<10; ++x) {}}
  • reference

    Code: Select all

    void f(int& x) { for (x=0; x<10; ++x) {}}
The C++ standard defines "variable" to include all of the above except for non-static class members.

However, other Misra rules like 0-1-3 seem to consider "variable" to include non-static class members and even bit fields.

Re: 6.5 - variable kinds suitable for use as loop counter

Posted: Mon Jul 10, 2017 11:14 am
by misra cpp
All your examples are acceptable as loop counters