skip to primary navigationskip to content
 

Course pages 2024–25

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.

Submission is/was via the Moodle page.

Moodle submission is now closed. Please resubmit minor corrections by sending by email your whole new zip file to [Javascript required]. Please make sure your crsid is in lower case in your folder name. For email submissions only, the zip name itself can have the crsid in it, like the zipped folder itself. The tick will be awarded (at the discretion of the Examiners) even if there are minor errors in the submission that was made before the deadline.

Your personal starter pack is HERE.

Only if you find that your starter pack zip has missing message files (two people reported this problem), please use these ones instead and make a note in your answers file. Please make sure your crsid is in lower case in your folder name.

For those called to Viva Voce or seeking assistance where their supervisor cannot help, please follow the viva slot announcements on HELP + VIVA DATES.

Primary Materials

Supervision Work and Examples Sheet

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

Note: Two variant sets of C++ supervision exercises exist. These are respectively at the end of the printed lecture notes and at the end of the above exercise sheet. They overlap with each other. Make sure all members of your supervision group attempt the same question cset!

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 on 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

  • Task 3 Lab notes (PDF)
  • Task 3 Lab package (.tar.gz format)
  • Of interest?: Dr Bjarne Stroustrup (creator of C++), when reading for his PhD at the Computer Laboratory, shared an office with Prof. Sir Andy Hopper (frwho was PhD supervisor to Dr David J Greaves (lecturer of this course)).

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).

DJG Absent or Late

DJG may be late or absent for the class on 25th October 2024. Sorry.

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 (Debugging)

Secondary Materials

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...