skip to primary navigationskip to content

Course pages 2021–22

Programming in C and C++

Assessed Exercise

The Part Ib C/C++ Assessed Exercise (tick) instructions are here PDF.

On or before Friday 3rd of December (end of Full Term), students will each be sent an email containing their personalised starter pack for this Exercise. A unique token for download of the starter pack will also be provided for use where email systems have blocked the attachment. The starter pack may contain watermarks, which means that files submitted by candidates are not interchangeable. Supervisors and other members of staff will be able to download a vanilla starter pack from the supervisors' tab for teaching purposes.

Submissions will be made by email, precisely following the pattern described in the instructions, since most of the submission is checked by computer. The submission deadline is 12 Noon, Mon 24 January 2022. Some candidates will be called for viva voce examination. Candidates will receive automated emails reporting the status of their submission, but the automated process is only run every few days, so this feedback is not instant. A supervisors or DoS can view their students' submission statuses via the Supervisor's tab.

If your submission is not correct, you will be notified and be able to re-submit. Do not change the name of your zip file for re-submission (unless it was accidentally wrong to start with). It is important to submit a substantially correct answer before the deadline, but a margin of at least four weeks exists beyond the deadline to allow for a correct re-submission.

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.

Course Structure

The first 9 slots are dedicated to C and the last 3 slots are dedicated to C++.

As in pre-covid days, session 1 (introduction to C) is being delivered in the lecture theatre. Pre-recorded lectures 2 to 9 should be watched in your own time.

The timetabled slots for sessions 2 to 9 are used for practical classes in the Intel Lab where DJG will be available. Outside of those slots, please consult your supervisor. Each of the eight practical classes has 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.

A ZOOM LINK THAT IS ACTIVE FOR REMOTE CONSULTATION DURING 8 PRACTICAL SESSIONS WILL BE HERE. You may need to press F5 to reload.

For the C++ sessions, numbered 10, 11 and 12, pre-recorded lecture videos are available.

In addition, Prof Mycroft WILL HOST A DROP-IN Q+A SESSION on Wed 3 Nov 12:30-13:30 on Zoom. Simply join the video-call at any time -- multiple listeners are encouraged, but please wait for a gap before speaking.

Practical assessment for this course will be via the formal written Assessed Exercise and subsequent viva voce session. The details will be above. Please ignore any remarks about the Assessed Exercise in the recorded lectures, since these may be out of date.

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.