Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) GcovExample1

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppGcovExample1/CppGcovExample1.pro

 

include(../../ConsoleApplication.pri) #Or use the code below
# QT += core
# QT += gui
# greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
# CONFIG   += console
# CONFIG   -= app_bundle
# TEMPLATE = app
# CONFIG(release, debug|release) {
#   DEFINES += NDEBUG NTRACE_BILDERBIKKEL
# }
# QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++
# unix {
#   QMAKE_CXXFLAGS += -Werror
# }

include(../../Libraries/Gcov.pri) #Or use the code below
# QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage
# QMAKE_LFLAGS += -lgcov -coverage

SOURCES += main.cpp

 

 

 

 

 

./CppGcovExample1/main.cpp

 

#include <iostream>

//Example adapted from https://en.wikipedia.org/wiki/Gcov
int main()
{
  for (int i = 1; i!=10; ++i)
  {
    if (i % 3 == 0)
    {
      std::cout << i << " is divisible by 3\n";
    }
    if (i % 11 == 0)
    {
      std::cout << i << " is divisible by 11\n";
    }
  }
}

/* Screen output:

3 is divisible by 3
6 is divisible by 3
9 is divisible by 3
Press <RETURN> to close this window...

*/

//After running the program, go to the executable's folder and type
//
// gcov main.gcda
//
// or
//
// gcov main.gcdo
//
// results in the following main.cpp.gcov:
//
#ifdef SHOW_UNMODIFIED_CONTENT

        -:    0:Source:../CppGcovExample1/main.cpp
        -:    0:Graph:main.gcno
        -:    0:Data:main.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:/*EOF*/
        -:    2:/*EOF*/
        -:    3:/*EOF*/
        1:    4:/*EOF*/
        -:    5:/*EOF*/
       10:    6:/*EOF*/
        -:    7:/*EOF*/
        9:    8:/*EOF*/
        -:    9:/*EOF*/
        3:   10:/*EOF*/
        -:   11:/*EOF*/
        9:   12:/*EOF*/
        -:   13:/*EOF*/
    #####:   14:/*EOF*/
        -:   15:/*EOF*/
        -:   16:/*EOF*/
        4:   17:/*EOF*/

#endif

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml