The purpose of this book is to get you strong enough in C that you’ll be able to write your own software in it, or modify someone else’s code. At the end of the book we actually take code from a more famous book called K&R C and code review it using what you’ve learned. To get to this stage you’ll have to learn a few things:
- The basics of C syntax and idioms.
- Compilation, make files, linkers.
- Finding bugs and preventing them.
- Defensive coding practices.
- Breaking C code.
- Writing basic Unix systems software.
By the final chapter you will have more than enough ammunition to tackle basic systems software, libraries, and other smaller projects.
Author:Zed A. Shaw
- Make is your Python now – a crash course in make, and you will be learning to use it as you learn C
- Formatted Printing
- Introducing Valgrind – an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail
- The Structure of a C Program – break down a simple C program line-by-line so you know how one is structured
- Types of Variables – integers, floating point, character, and string
- More Variables, Some Math – more things you can do with variables by declaring various ints, floats, chars, and doubles. Then use these variables in various math expressions so you get introduced to C’s basic math
- Sizes and Arrays – introduces a few more concepts: sizeof and arrays
- Arrays of Strings, Looping – shows you that C stores its strings simply as an array of bytes, terminated with the ‘\0’ (nul) byte
- While-Loop and Boolean Expressions – see how a while-loop works
- If, Else-If, Else – something common in every language is the if-statement, and C has one
- Switch Statement – some code that we will break down to understand this concept of “jump tables”
- Writing and Using Functions – write some functions and use some other functions
- Pointers Dreaded Pointers – demystifies pointers
- Structs and Pointers to them – learn how to make a struct, point a pointer at them, and use them to make sense of internal memory structures
- Heap and Stack Memory Allocation – create an entire small program to manage a database
- Pointers to Functions – functions in C are actually just pointers to a spot in the program where some code exists
- A Simple Object System – this exercise will build a simple game where you kill a Minotaur in a small little castle
- Zed’s Awesome Debug Macros – a small set of “debug macros” that implement a basic debugging and error handling system for C
- Advanced Data Types and Flow Control – this exercise will be a complete compendium of the available C data types and flow control structures you can use
- The Stack, Scope, and Globals – learn about scope by learning about how a stack data structure works, and then feeding that concept back in to how modern C does scoping
- Meet Duff’s Device – this exercise is a brain teaser introducing a famous hack in C
- Input, Output, Files – use the functions fscanf and fgets to build information about a person in a structure. After this simple introduction to reading input, you will get a full list of the functions that C has for I/O
- Variable Argument Functions – knowing how a variable argument function works helps debug them and provides a greater understanding of the computer
- Write a First Real Program – recreate a piece of software, devpkg – a simple C program that installs other software
- Creative and Defensive Programming – advanced concepts and feature more talking than code
- Intermediate Makefiles – create a skeleton project directory to use in building your C programs later
- Libraries and Linking – learning how C links things helps you understand how your OS works and how it runs your programs
- Automated Testing – used frequently in other languages like Python and Ruby, but rarely used in C
- Debugging Code – Debug Printing vs GDB vs Valgrind
- Double Linked Lists
- Linked List Algorithms – covers two algorithms you can do on a linked list that involve sorting
- Dynamic Array – an array that grows on its own and has most of the same features as a linked list
- Sorting and Searching – covers four sorting algorithms and one search algorithm
- Safer Strings – designed to get you into using bstring from now on, why C’s strings are an incredibly bad idea, and then have you change the liblcthw code to use bstring
- Hashmaps – Hash Maps (Hashmaps, Hashes, or sometimes Dictionaries) are used frequently in many dynamic programming for storing key/value data
- Hashmap Algorithms – implement three hash functions: FNV-1a, Adler-32, and DJB Hash
- String Algorithms – gist of this algorithm is that it calculates a “skip characters list” as a first operation, then it uses this list to quickly scan through the string
- Binary Search Trees – the simplest tree based data structure
- Using Cachegrind and Callgrind for Performance Tuning – a quick course in using two tools for Valgrind called callgrind and cachegrind
- Stacks and Queues – very simple data structures that are really variants of the List data structure
- A Simple Statistics Engine – a simple algorithm used for collecting summary statistics “online”
- Ring Buffer – useful when processing asynchronous IO. They allow one side to receive data in random intervals of random sizes, but feed cohesive chunks to another side in set sizes or intervals
- A Simple TCP/IP Client – use the RingBuffer to create a very simplistic little network testing tool called netclient
- Ternary Search Tree
- A Fast URL Router – use the TSTree to do fast URL routing in web servers
- A Tiny Virtual Machine – implements a version of the DCPU16 virtual machine using the algorthms created previously
This book is free for you to read, but until I’m done you can’t distribute it or modify it. I need to make sure that unfinished copies of it do not get out and mess up a student on accident.