skip to primary navigationskip to content
 

Course pages 2025–26

Programming in C and C++

Course Structure

There are 12 slots timetabled for this course. The first 9 slots are dedicated to C and the last 3 slots are dedicated to C++.

Slot 1 has a lecture (introduction to C) delivered in LT1. The pre-recorded lectures for slots 2 to 9 should be watched in your own time. The C++ lectures, numbered 10, 11 and 12, will also be given in LT1.

The timetabled slots for sessions 2 to 9 are used for practical lab sessions 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.

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

As stated above, the 8 practical lab sessions are not assessed: it is recommended to attened, but this is in no way compulsorary.

Assessed Exercise (Tick)

There is one Assessed Exercise for this course... details to follow...

All further details for this year will be here soon. Compared with last year, nearly everything will be the same.

Primary Materials

Supervision Work and Examples Sheet

C Example Sheets - CURRENTLY MISSING - under construction.

This ProgC Exercise Sheet might prove useful for supervision questions regarding C. CURRENTLY MISSING.

For C++ this sheet may be useful: CURRENTLY MISSING.

Note: Two variant sets of C++ supervision exercises are just being merged for this year...

Lab Programming Tasks and per-lecture tasks and remarks

There are 8 Lab programming tasks in C and one C/C++ Assessed Exercise

  • These programming tasks are informal and not ticked. You may collaborate with others during these as much as you like.
  • On the other hand, the Assessed Exercise must be your own work and its details will be announced at the top of this page in due course.

Session 1

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

#include <stdio.h>

int main()
{
  printf("Hello World!\n");
  return 0;
}

Try also the demo from Concurrent Systems L1: l1-interleaving-demo.zip.

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 language often ran on word-addressed machines, so the normal pointer de-referencing operator (asterisk in C, pling (exclamation mark) in BCPL) could not fetch individual 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 (a past lecturer of this course), together with Dr Arthur Norman (of the Computer Laboratory) and others, wrote the first C compiler for the Arm processor (an ISA that 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 closed subroutine (today often called a method or function). The machine instruction to call a clsoed 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 integrated circuits 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 (Debugging)

Secondary Materials

C: A Reference Manual (Vth ediiton) PDF.

For those with further interest ...

  • Systems Design, 12 Lectures to Part Ia (PDF, 96 pages) Note part III of these notes relates to link editing.

  • hello-world-in-linux-assembly-language. This provides a concrete example of making a system call.

  • Additional lecture video regarding Undefined Behaviour. This video provides coverage of undefined behaviour, going into more detail than required for this course. However, you may find the specific examples interesting. Also, variations of these behaviours are often asked about in examination questions for the Semantics course.

  • The Rust language is becomming a realistic replacement for C. Its fierce type system prevents a number of memory management problems that can arise in C and C++. You might like to learn it within the next five years... Torvalds talks Rust in the Linux kernel.

  • Further materials might be placed here...

Last year’s course materials are still available.