skip to primary navigationskip to content

Course pages 2020–21

Programming in C and C++

Assessed Exercise

The instructions for the assessed exercise are on this sheet CC++exercise2021.pdf.

The submission deadline is the 25th January 2021, with a follow-up zoom viva for a randomly-selected subset on the Thursday or Friday of the same week. Please be ready to share your screen in the viva where you should be displaying your files. The viva will consist of two or three fairly quick questions where you demonstrate that you fully understand your work.

The starter pack is starter_pack.tgz.

Your DoS will have access to a table showing whether your submission has been received and the ticking status. Additionally, you will receive an automated feedback email during the week of 25th January 2021 informing you of outcome: pass outright, viva details, minor corrections required, etc..

Lecture Notes

  • Programming in C (lectures 1-9, DJ Greaves). Slides.
  • Programming in C++ (lectures 10-12, A Mycroft). Slides (alternatively 4-up)
  • This exercise sheet might prove useful for supervision questions on C and C++.
  • All Class Task Sheets (lectures 2-9). Lab Practical Exercises PDF. (These are the same as the concatenated "Session and Lab notes" below.)
  • Lecture videos are on the `recordings' tab above.
  • Errata (corrected in PDF above, slides as printed for comparison):
    • C++ slide 40, "bool panniers" (previously "int")
    • C++ slide 73, "struct fact" (previously "fact fact")

Course Structure

All lectures are pre-recorded this year in video format.

In previous years, session 1 (introduction to C) and sessions 10, 11 and 12 (C++) were delivered in a lecture theatre.

The remaining sessions, 2 to 9, are practical classes, each with a task. DJ Greaves will be available by Zoom or similar (details to be announced) during the timetabled slots for those sessions. Outside of those slots, please consult your supervisor. These practical classes all have a task to complete, but these are not assessed in any way, so please feel free to collaborate as much as you want, but don't just hand out your own answer.

Practical assessment will be via the formal Assessed Exercise and viva voce session, details below.

For the first 9 sessions, assistance from the lecturer is likely to be available during the timetabled slot, starting at 15 minutes past the hour. When a help session with the lecturer is currently available and active, the zoom link for the session, for local access only, will be HERE.

Exercises and per-lecture tasks and remarks

There are 8 programming tasks in C and one Assessed Exercise

  • The programming tasks are informal and not ticked.
  • The Assessed Exercise will be announced in Week 3 or 4 of term.
  • Both are explained in greater detail below.

Session 1

There is no associated task 1, except to gain access to a C compiler and repeat one of the demos from lecture 1.

Session 2

Session 3

Session 4

Note: The video and slides for Lecture 4 may mention a previous year's Assessed Exercise (tick). This is not quite the same as this year's tick.

  • Task 4 Lab notes (PDF)
  • Task 4 Lab package (.tar.gz format))
  • Of interest?: The BCPL lanugage often ran on word-addressed machines, so the normal pointer de-referencing operator (asterisk in C, pling (exclamation mark) in BCPL) could not fetch individal bytes in memory (as needed for character strings) and hence a separate operator was provided in BCPL (using the percent sign).

Session 5

  • Task 5 Lab notes (PDF)
  • Task 5 Lab package (.tar.gz format)
  • Of interest?: Prof Alan Mycroft (lecturer of this course), together with Dr Arthur Norman (of the Computer Laboratory) and others, wrote the first C compiler for the ARM processor (which runs the apps in every mobile phone).

Session 6

  • Task 6 Lab notes (PDF)
  • Task 6 Lab package (.tar.gz format)
  • Of interest?: Prof David J Wheeler (PhD examiner to Dr David J Greaves (lecturer of this course)) invented the subroutine (today often called a method or function). The machine instruction to call a subroutine (which saves the address of the following instruction) was first called the Wheeler Jump. But now it is often called call (sic).

Session 7 (String Matching)

  • Erratum (on video?): The arguments to set_left where we are making a loop should be n1 instead of node1, etc..
  • Task 7 Lab notes (PDF)
  • Task 7 Lab package (.tar.gz format)
  • Of interest?: The C-- backend language is a C-like programming language whose creators include Dr S Peyton-Jones of the Computer Laboratory. It is intended to be generated mainly by compilers for very high-level languages rather than written by human programmers. Unlike many other intermediate languages, its representation is plain ASCII text, not bytecode or another binary format.

Session 8 (Caches)

  • Task 8 Lab notes (PDF)
  • Task 8 Lab package (.tar.gz format)
  • Of interest?: In 1999, Dr David J Greaves (lecturer of this course), wrote a program that converted Verilog to C++. Hundreds of chip companies used this program to generate fast software models of ICs that did not yet exist. When a whole chip was converted, the output was sometimes a C++ program of millions of lines in length. It consisted mainly of one basic block (per clock domain) containing straight-line code. Such blocks were called once per modelled clock cycle and as a result, there was no temporal locality in the instruction caches. This degraded performance, but the tool was still useful. GNU gcc handled the generated code with no problem. Special adaption was required to overcome Visual C's limitations such as parenthesis nesting of greater than 255 levels or structs with thousands of fields.

Session 9

Supervision Work and Examples Sheet

This exercise sheet might prove useful for supervision questions on C and C++.

Installing a Virtual Machine Image

[Is this out-of-date now? Installing virtual box is almost certainly more complex than installing gcc or llvm.]

If you do not have gcc or llvm installed on your laptop, then:

  1. Download a

    virtual machine image for Ubuntu Linux with gcc and llvm installed.

  2. Go to the the VirtualBox website to find out how to install the VirtualBox software on your machine.