Details

    • Type: Sub-task Sub-task
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.3.1
    • Component/s: None
    • Labels:
      None

      Description

      C99 allows you to declare iterator variables within "for" loops, but C89 does
      not:

          // C99
          for (int i = 0, max = 10; i < max; i++) {
              // ...
          }
      
          /* C89 */
          int i, max;
          for (i = 0, max = 10; i < max; i++) {
              /* ... */
          }
      

      The C99 idiom is superior because it limits the scope of the iterator
      variable.

      We have a number of C89-style iterator variables which should be switched
      over. In some cases, the iterator variable is declared at the top of a scope
      and then reused within several loops. That's the sort of pattern we'd like to
      avoid.

      The following crude grep command detects some candidates which ought to be
      reviewed:

      grep -r "for ([a-z] =" lucyalt | grep -v -e "svn\|charmonizer\|modules\|\.pm"
      

      Care must be taken when performing this refactoring, because some code may
      in fact be relying on iterator variables holding values across multiple
      loops – such as in PriorityQueue.c. It will be good when this refactoring
      pass is finished because such code will stand out more.

        Activity

          People

          • Assignee:
            Logan Bell
            Reporter:
            Marvin Humphrey
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development