Fork me on GitHub

Project Notes

21st Century C

Notes on the book 21st Century C, 2nd Edition by Ben Klemens, pubished by O’Reilly



Highlights from the Table of Contents

  • Preface
  • C Is Punk Rock
  • Q & A (Or, the Parameters of the Book)
  • Standards: So Many to Choose From

I. The Environment

1. Set Yourself Up for Easy Compilation

  • Use a Package Manager
  • Compiling C with Windows
  • Runtime Linking
  • Using Makefiles
  • Using Libraries from Source

Good practical introduction to setting up a working environment:

  • compiler: gcc / clang
  • debugger: gdb
  • profiler: gprof
  • make
  • Valgrind, to test for C memory usage errors
  • pkg-config, for finding libraries.
  • Doxygen, for documentation generation
  • A text editor

Later chapters cover: Autotools: Autoconf, Automake, libtool

2. Debug, Test, Document

  • Using a Debugger
  • Using Valgrind to Check for Errors
  • Unit Testing
  • Error Checking
  • Interweaving Documentation

3. Packaging Your Project

Makefiles vs. Shell Scripts Packaging Your Code with Autotools

4. Version Control

Covers basics of git.

5. Playing Nice with Others

  • Dynamic Loading
  • Python Host

II. The Language

6. Your Pal the Pointer

  • Automatic, Static, and Manual Memory
  • Persistent State Variables
  • Pointers Without malloc

7. Inessential C Syntax that Textbooks Spend a Lot of Time Covering

  • Don’t Bother Explicitly Returning from main
  • Let Declarations Flow
  • Set Array Size at Runtime
  • Cast Less
  • Enums and Strings
  • Labels, gotos, switches, and breaks
  • Deprecate Float
  • Comparing Unsigned Integers
  • Safely Parse Strings to Numbers

8. Important C Syntax that Textbooks Often Do Not Cover

  • Cultivate Robust and Flourishing Macros
  • Linkage with static and extern
  • The const Keyword

9. Easier Text Handling

  • Making String Handling Less Painful with asprintf
  • A Pæan to strtok
  • Unicode

10. Better Structures

  • Compound Literals
  • Variadic Macros
  • Safely Terminated Lists
  • Multiple Lists
  • Foreach
  • Vectorize a Function
  • Designated Initializers
  • Initialize Arrays and Structs with Zeros
  • Typedefs Save the Day
  • Return Multiple Items from a Function
  • Flexible Function Inputs
  • The Void Pointer and the Structures It Points To

11. Object-Oriented Programming in C

Shows how to use OOP concenpts in C with a couple of full examples.

12. Parallel Threads

  • OpenMP
  • Thread Local
  • Shared Resources
  • Pthreads
  • C atoms

13. Libraries

  • GLib - libGlib
  • The GNU Scientific Library - libGSL
  • SQLite - libSQLite3
  • libxml and cURL (libXML2, libcURL)


Provides a very good “C 101”

Getting the Example Source

The git repo actually contains a ziped archive of the sources. I’ve extracted locally to a folder called example_source as follows:

$ git clone
$ tar zxvf 0636920025108/21st_century_examples.tgz
$ mv 21st_century_examples example_source
$ rm -fR 0636920025108

Credits and References

About LCK#115 Cbook
Project Source on GitHub Return to the Project Catalog

This page is a web-friendly rendering of my project notes shared in the LittleCodingKata GitHub repository.

LittleCodingKata is my collection of programming exercises, research and code toys broadly spanning things that relate to programming and software development (languages, frameworks and tools).

These range from the trivial to the complex and serious. Many are inspired by existing work and I'll note credits and references where applicable. The focus is quite scattered, as I variously work on things new and important in the moment, or go back to revisit things from the past.

This is primarily a personal collection for my own edification and learning, but anyone who stumbles by is welcome to borrow, steal or reference the work here. And if you spot errors or issues I'd really appreciate some feedback - create an issue, send me an email or even send a pull-request.