Programming in C and C++
Principal lecturer: Dr David Greaves
Taken by: Part IB CST
Term: Michaelmas
Hours: 12
Format: In-person lectures
Suggested hours of supervisions: 3
Exam: Paper 4 Question 5, 6
Past exam questions, Moodle, timetable
Aims
This course aims
- to provide a solid introduction to programming in C and to provide an overview of the principles and constraints that affect the way in which the C programming language has been designed and is used;
- to introduce the key additional features of C++.
Lectures
- Introduction to the C language. Background and goals of C. Types, expressions, control flow and strings.
- (continued) Functions. Multiple compilation units. Scope. Segments. Incremental compilation. Preprocessor.
- (continued) Pointers and pointer arithmetic. Function pointers. Structures and Unions.
- (continued) Const and volatile qualifiers. Typedefs. Standard input/output. Heap allocation. Miscellaneous Features, Hints and Tips.
- C semantics and tools. Undefined vs implementation-defined behaviour. Buffer and integer overflows. ASan, MSan, UBsan, Valgrind checkers.
- Memory allocation, data structures and aliasing. Malloc/free, tree and DAG examples and their deallocation using a memory arena.
- Further memory management. Reference Counting and Garbage Collection
- Memory hierarchy and cache optimization. Data structure layouts. Intrusive lists. Array-of-structs vs struct-of-arrays representations. Loop blocking.
- Debugging. Using print statements, assertions and an interactive debugger. Unit testing and regression.
- Introduction to C++. Goals of C++. Differences between C and C++. References versus pointers. Overloaded functions.
- Objects in C++. Classes and structs. Destructors. Resource Acquisition is Initialisation. Operator overloading. Virtual functions. Casts. Multiple inheritance. Virtual base classes.
- Other C++ concepts. Templates and meta-programming.
Objectives
At the end of the course students should
- be able to read and write C programs;
- understand the interaction between C programs and the host operating system;
- be familiar with the structure of C program execution in machine memory;
- understand the potential dangers of writing programs in C;
- understand the object model and main additional features of C++.
Recommended reading
* Kernighan, B.W. and Ritchie, D.M. (1988). The C programming language. Prentice Hall (2nd ed.).