Practical Programming Methodology

Programming in C on Unix: why C and the Unix environment matter, the preprocessor, compiler, assembler and linker, types, conversions and undefined behavior, functions, scope and the call stack, pointers, arrays and strings with buffer-overflow prevention, heap memory and ownership with AddressSanitizer and Valgrind, structs, unions and padding, linked lists, dynamic arrays and hash tables, files and error handling with errno and strtol, make, gdb and unit testing, and a capstone command-line tool built with Unix tools, Git, code review, licenses and professional ethics.

CMPUT-201 Year 2 3 credits 12 lessons · 5 h 56 min

Offered by HSM University · Computing Science

This is the American version of this course. See the Canadian version.

What you'll learn

  • Explain why C remains central to systems software, how it differs from Python, and work in the Unix environment with gcc, warnings and the sanitizers from the first program.
  • Describe the preprocessing, compiling, assembling and linking stages, organize programs into headers and separately compiled source files, link libraries, and tell compiler errors from linker errors.
  • Use C's integer, floating-point, fixed-width and Boolean types correctly, predict integer division, conversions and overflow, apply bitwise operators, and write if, switch and loop statements.
  • Define and declare functions, explain pass-by-value, scope, linkage and storage duration, trace the call stack through recursive calls, and design module interfaces in header files.
  • Use pointers, the & and * operators, NULL, pointer arithmetic, pointers to pointers, const and void * correctly, and recognize null, uninitialized and dangling pointers.
  • Work with arrays and C strings, explain array-to-pointer decay and the null terminator, use string.h and snprintf safely, process command-line arguments, and prevent buffer overflows.
  • Allocate, resize and free heap memory with malloc, calloc, realloc and free, assign clear ownership to every block, and find leaks, use after free and double free with AddressSanitizer and Valgrind.
  • Define structs, enums, unions and tagged unions, pass structs by pointer, and explain alignment, padding, offsetof and why raw struct layouts are not portable.
  • Implement linked lists, stacks, dynamic arrays and chained hash tables with complete cleanup, use function pointers with qsort, and hide implementations behind opaque types.
  • Read and write text and binary files through streams, check every library return value, report errors with errno and strerror, convert text to numbers with strtol, and release resources on every path.
  • Build projects with make, debug with gdb using breakpoints and backtraces, write unit tests with assertions and test macros, and use static analysis and coverage to find untested and faulty code.
  • Design, implement and test a Unix command-line tool that works in pipelines, manage it with Git and code review, choose and respect software licenses, and apply the ACM and IEEE Computer Society codes of ethics.

Course content

12 lessons · 5 h 56 min total · final exam

  1. 1 Why C and the Unix environment 33 min · quiz
  2. 2 The compilation pipeline and the toolchain 29 min · quiz
  3. 3 Types, operators and control flow in C 29 min · quiz
  4. 4 Functions, scope, the stack and header files 29 min · quiz
  5. 5 Pointers and addresses 31 min · quiz
  6. 6 Arrays, strings and memory safety 29 min · quiz
  7. 7 Dynamic memory and the heap 29 min · quiz
  8. 8 Structs, unions and data layout 29 min · quiz
  9. 9 Data structures in C 29 min · quiz
  10. 10 Files, the standard library and error handling 30 min · quiz
  11. 11 Building, debugging and testing 27 min · quiz
  12. 12 Capstone: a command-line tool, Unix tooling and professional practice 32 min · quiz
  13. E Final exam 20 questions

Requirements

Recommended background. You can start any course at any time.

Description

Programming in C on Unix: why C and the Unix environment matter, the preprocessor, compiler, assembler and linker, types, conversions and undefined behavior, functions, scope and the call stack, pointers, arrays and strings with buffer-overflow prevention, heap memory and ownership with AddressSanitizer and Valgrind, structs, unions and padding, linked lists, dynamic arrays and hash tables, files and error handling with errno and strtol, make, gdb and unit testing, and a capstone command-line tool built with Unix tools, Git, code review, licenses and professional ethics.

Part of the Science stream, typically taken in year 2.