scitools.com

← Metric catalog

Globals Used/Set/Modified is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.

Globals Used/Set/Modified

API ID: CountGlobalsUsedSetModified
Languages: C, C++, Pascal, Python, Web
Targets: Functions

The number of uses, sets, or modifications to global objects by this function

Example:

    int my_global = 10;
    void combined(int x)
    {
      int y, z;

      x ++;                //     Parameters do not count
      if (x > 10)          //     Parameters do not count
        x = 0;             //     Parameters do not count

      y ++;                //     Locals do not count
      if (y > 10)          //     Locals do not count
        y = 0;             //     Locals do not count

      my_global ++;        // + 1 Globals count
      if (my_global > 10)  // + 1 Duplicates count
        my_global= 0;      // + 1 Duplicates count
    }                      // CountGlobalsUsedSetModified = 9
    

Compare to CountGlobalsUsedSetModifiedUnique which counts unique global objects this function uses, sets, and/or modifies.