Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-1705

The prefix increment/decrement form should be used

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Use prefix (increment|decrement)
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Covered Languages:
      C, C++, Objective-C
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min
    • CPPCheck:
      postfixOperator

      Description

      Postfix increment and decrement typically involves making a copy of the object being incremented or decremented, whereas its prefix form does not. Therefore the prefix form is usually the more efficient form, and should be preferred.

      Noncompliant Code Example

      void myFunc(int lim)
      {
        int i;
        for (i = 0; i < lim; i++)
        {
          // do something
        }
      }
      

      Compliant Solution

      void myFunc(int lim)
      {
        int i;
        for (i = 0; i < lim; ++i)
        {
          // do something
        }
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ann.campbell.2 Ann Campbell
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: