Headline

Graph of paths through a program that may be executed

Citation

(https://en.wikipedia.org/wiki/Control_flow_graph, 12 November 2015)

In a control flow graph each node in the graph represents a basic block, i.e., a straight-line piece of code without any jumps or jump targets; jump targets start a block, and jumps end a block. Directed edges are used to represent jumps in the control flow.

Illustration

Consider the following implementation of Factorial in Language:C

int factorial(int n) {
  int r = 1;
start:
  if (n<=0) 
    goto end;
  r = r * n;
  n = n - 1;
  goto start;
end:
  return r;
}

The following version assign block ids (A)-(D) to all lines that are gotos or targets thereof.

int factorial(int n) {
(A)   int r = 1;
    start:
(B)   if (n==0)
        goto end;
(C)   r = r * n;
(C)   n = n - 1;
      goto start;
    end:
(D)   return r;
}

By taking into account jumps and branching due to selection, we derive the following edges:

  • (A) -> (B)
  • (B) -> (D)
  • (B) -> (C)
  • (C) -> (B)
See also the illustration of spaghetti code where a C program is annotated with some edges of a control-flow graph.


There are no revisions for this page.

User contributions

    This user never has never made submissions.

    User edits

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.