Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Zed A. Shaw

Rating No ratings yet

"Please don’t feel cheated, but this book is not about teaching you C programming. You’ll learn to write programs in C, but the most important lesson you’ll get from this book is rigorous defensive programming. Today, too many programmers simply assume that what they write works, but one day it will fail catastrophically. This is especially true if you’re the kind of person who has learned mostly modern languages that solve many problems for you. By reading this book and following my exercises, you’ll learn how to create software that defends itself from malicious activity and defects. I’m using C for a very specific reason: C is broken. It is full of design choices that made sense in the 1970s but make zero sense now. Everything from its unrestricted, wild use of pointers to its severely broken NUL terminated strings are to blame for nearly all of the security defects that hit C. It’s my belief that C is so broken that, while it’s in wide use, it’s the most difficult language to write securely. I would fathom that Assembly is actually easier to write securely than C. To be honest, and you’ll find out that I’m very honest, I don’t think that anybody should be writing new C code. If that’s the case, then why am I teaching you C? Because I want you to become a better, stronger programmer, and there are two reasons why C is an excellent language to learn if you want to get better. First, C’s lack of nearly every modern safety feature means you have to be more vigilant and more aware of what’s going on. If you can write secure, solid C code, you can write secure, solid code in any programming language. The techniques you learn will translate to every language you use from now on. Second, learning C gives you direct access to a mountain of legacy code, and teaches you the base syntax of a large number of descendant languages. Once you learn C, you can more easily learn C++, Java, Objective-C, and JavaScript, and even other languages become easier to learn."

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A deliberately unforgiving, exercise-driven introduction to C that uses the language's notorious unsafety to teach rigorous defensive programming, debugging discipline, and low-level systems thinking. Best for programmers who already know one language and want to understand the machine, memory, and their own failure modes. 【Book Arc】 - **Opening (~0%–15%)**: Frames the book's contrarian thesis—C is broken, but learning it makes you stronger—and sets expectations for defensive programming over syntax memorization. - **Early (~15%–30%)**: Tooling and first contact: setup, compilers, Make, formatted printing, and Valgrind as a constant companion for finding memory errors. - **Middle (~30%–55%)**: Core C fundamentals: program structure, variables, arrays, strings, control flow, functions, pointers, structs, heap/stack allocation, and function pointers. - **Late (~55%–80%)**: Intermediate systems work: I/O and files, variadic functions, Makefiles, libraries and linking, automated testing, debugging, and safer string handling. - **Ending (~80%–100%)**: Data structures and applied projects: linked lists, dynamic arrays, sorting/searching, hashmaps, binary search trees, ring buffers, a TCP/IP client, a URL router, and a tiny virtual machine. 【Key Takeaways】 - **Defensive programming is the real subject** (Opening): The book explicitly says it is not primarily a C tutorial; it trains you to assume your code will fail and to build software that resists defects and malicious input. - **C's lack of safety is the teaching tool** (Opening): Because C hides almost nothing, you must be vigilant about memory, pointers, and strings—skills that transfer to every other language. - **Tooling comes before syntax** (Early): Make, compiler warnings, and Valgrind are introduced early so you can detect and diagnose mistakes from the very first exercises. - **"How To Break It" is a core method** (Early–Middle): Each exercise asks you to deliberately crash, corrupt, or misuse your program, turning failure into the primary learning mechanism. - **Pointers and memory are unavoidable** (Middle): Heap vs. stack allocation, pointer arithmetic, and structs are treated as essential, not optional, because they are where C programs break. - **Real programs are the goal** (Late–Ending): The book moves from small exercises to linked lists, hashmaps, trees, a TCP/IP client, a URL router, and a tiny virtual machine, so you finish with systems-level building blocks. - **Independence is part of the curriculum** (Late): Extra-credit research and self-directed debugging are framed as habits that build confidence and reduce reliance on others. - **Unix is the assumed environment** (Early): Linux and macOS are treated as natural homes for C; Windows users are steered toward a virtualized Ubuntu setup to avoid toolchain friction. 【Reading Tips】 - **Do the exercises, don't just read them.** The book's value is in typing, compiling, breaking, and fixing code; passive reading will not build the defensive instincts it promises. - **Deep-read the tooling chapters (Make, Valgrind, debugging).** These early exercises are short but set up the rest of the book; skimming them makes later debugging much harder. - **Treat "How To Break It" as mandatory.** Deliberately causing segfaults and memory errors is where the defensive-programming lesson actually lands. - **Expect Windows friction.** If you're on Windows, follow the book's advice and use a Linux VM rather than fighting the native toolchain. - **Use the later data-structure and project chapters as checkpoints.** If you can build and debug the linked list, hashmap, and tiny VM exercises, you've absorbed the core of the book. 【Coverage Limits】 The excerpts cover the preface, table of contents, setup, early tooling, and the first few exercises in detail, but do not include the full text of the later data-structure and virtual-machine chapters. This guide therefore describes the book's arc and method rather than every exercise's specific implementation.
Excerpt 1
u the base syntax of a large number of descendant languages. Once you learn C, you can more easily learn C++, Java, Objective-C, and JavaScript, and even oth...
View in text
Excerpt 2
ven other languages become easier to learn." Cover
View in text
Excerpt 3
mail help@learncodethehardway.org to report any problems.
View in text
Excerpt 4
seductive talk of pointers and direct access to the machine. Then, once this computational Lucifer has you hooked, he destroys your world with the evil "segf...
View in text
Excerpt 5
er's editor like Vim or Emacs, makes you work with the code. It's a little harder, but the end result is you can work with any code, on any computer, in any...
View in text
Excerpt 6
'height' is used uninitialized in this function $ valgrind ./ex4 ==3082== Memcheck, a memory error detector ==3082== Copyright (C) 2002-2010, and GNU GPL'd,...
View in text
Excerpt 7
hat number using %ld which adds a modifier to the usual %d . Adding 'l' (the letter ell) means "print this as a long decimal". ex7.c:15-17 Just more math and...
View in text
Excerpt 8
oo many 'a' characters and no space for the '\0' terminator. Try to come up with some other ways to break this, and as usual run all of these under Valgrind...
View in text
Tags
AI categories
Programming LanguageSoftware
c
Publisher: Addison-Wesley
Publish Year: 2016
Language: English
Pages: 386
File Format: EPUB
File Size: 279.2 KB