Locness Rules of Counting

Unfortunately, no standards organizations (ANSI, ISO, etc) has come up with a policy on how to count source code in any language.  So I came up with my own rules which is quite open for debate.  C++ is a vast language so I haven't included every possible way of counting.  Therefore, the program as well as this section here could (and probably would) change in the future.   So here goes....

Classes

  •  A class definition along with all its modifiers and parent definitions counts as 1 LOC.  Subclasses are their own definitions so each counts as 1 LOC as well.

    • class a : public b, // 1 LOC for class a but not for b and c

          public c

      {

          class d // 1 LOC

          {

          };

      };

  • A class referred in a method definition does not count as LOC.

    • void a::funct1()  // class a not counted

      {

      }

  • Template, structure, union, and enum definitions are counted like classes.

Functions

  • Function prototypes/declarations are counted as well as definitions.

    • void funct1(); // 1 LOC

       

      woid funct1()  // 1 LOC

      {

          int a;

      }

  • Arguments and intialization count as elements so they affect the element count.

    • void x::funct1(int a, int b) : y() // 1 function, 2 variables, 1 init

      {

      }

Variables

  • Each variable declaration counts as a LOC even when declaring multiple variables at once.

    • int a;          // 1 LOC

      short b, c, d;  // 3 elements

  • Declaration an initialization counts as separate elements.

    • int a = 0;   // 2 elements

       

      int b = 1, c = 2; // 2 variables, 2 initialization statements

Statements

  • A statement ending with a semicolon counts as a LOC even if it spans multiple lines.
  • Preprocessor directives are counted.

    • #define __HI__          // 1 LOC

      #define __BYE__ \

          GOODBYE             // 1 LOC, continued from previous line

       

  • Switch and its case labels each count as a LOC.

    • switch(a)       // LOC

      {

      case 1:         // LOC

      case 2:         // LOC

         ...

       

      default:        // LOC

         ...

      }

  • An If-Else pair counts as 1 LOC.  For nested branches, each pair is counted as 1 LOC.

    • if (a == 1)  // 1 LOC

          ...;

      else         // not counted separately

          ...;

       

      if (b == 1)           // 1 LOC

          ...

      else if (b == 2)      // 1 LOC for the if

          ...

      else                  // not counted separately

          ...

  • Looping constructs such as the do, while, and for, count as LOCs.

    • do             // 1 LOC

          ...

      while (true);  // not counted separately

       

       

      while(true)   // 1 LOC

          ...

       

       

      for(a=0;a<10;a++)   // 1 LOC

          ...
       

  • Try-Catch constructs count as a LOC, however additional catch statements counts separately.
    •  

      try            // 1 LOC

      {

          ...

      }

      catch(int a)   // not counted separately

      {

          ...

      }

      catch(...)     // 1 LOC

      {

          ...

      }

 

<< Introduction

 

 

1