From f39adf0e18a94d4d309735d7187af3733af923ab Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 5 Sep 2011 16:02:31 -0700 Subject: [PATCH] Laid out the structure of a big part of the book. --- ex14.tex | 15 ++++++++++++++- ex15.tex | 16 +++++++++++++++- ex16.tex | 21 ++++++++++++++++++++- ex17.tex | 15 ++++++++++++++- ex18.tex | 19 ++++++++++++++++++- ex19.tex | 22 +++++++++++++++++++++- 6 files changed, 102 insertions(+), 6 deletions(-) diff --git a/ex14.tex b/ex14.tex index 4ba58c8..bc9c2a8 100644 --- a/ex14.tex +++ b/ex14.tex @@ -1,8 +1,21 @@ -\chapter{Exercise 14} +\chapter{Exercise 14: Writing And Using Functions} +Until now you've just used functions that are part of the +\file{stdio.h} header file. In this exercise you will write +some functions and use some other functions. + +\begin{code}{ex14.c} +<< d['code/ex14.c|pyg|l'] >> +\end{code} \section{What You Should See} +\begin{code}{ex14 output} +\begin{lstlisting} +<< d['code/ex14.out|dexy'] >> +\end{lstlisting} +\end{code} + \section{How To Break It} diff --git a/ex15.tex b/ex15.tex index 800d2dd..f173b76 100644 --- a/ex15.tex +++ b/ex15.tex @@ -1,8 +1,22 @@ -\chapter{Exercise 15} +\chapter{Exercise 15: Pointers Dreaded Pointers} +Pointers are famous mystical creatures in C that I will attempt to +demystify by teaching you the vocabulary used to deal with them. They +actually aren't that complex, it's just they are frequently abused +in weird ways that make them hard to use. If you avoid the stupid +ways to use pointers then they're fairly easy. + +\begin{code}{ex15.c} +<< d['code/ex15.c|pyg|l'] >> +\end{code} \section{What You Should See} +\begin{code}{ex15 output} +\begin{lstlisting} +<< d['code/ex15.out|dexy'] >> +\end{lstlisting} +\end{code} \section{How To Break It} diff --git a/ex16.tex b/ex16.tex index e481ca3..18b8f55 100644 --- a/ex16.tex +++ b/ex16.tex @@ -1,8 +1,27 @@ -\chapter{Exercise 16} +\chapter{Exercise 16: Structs And Pointers To Them} +While it's useful to have all the various data types C has, +it's more useful to package them into a cohesive container. +A \ident{struct} is how C creates cohesive records, and the +closest construct you might know is classes and objects. However, +\ident{structs} predate Object Oriented Programming so they're +not quite the same. + +In this exercise you'll learn how to make a \ident{struct}, +create an array of them, point a pointer at them, and use them +to make sense of internal memory structures. + +\begin{code}{ex16.c} +<< d['code/ex16.c|pyg|l'] >> +\end{code} \section{What You Should See} +\begin{code}{ex16 output} +\begin{lstlisting} +<< d['code/ex16.out|dexy'] >> +\end{lstlisting} +\end{code} \section{How To Break It} diff --git a/ex17.tex b/ex17.tex index db6d98e..860356a 100644 --- a/ex17.tex +++ b/ex17.tex @@ -1,8 +1,21 @@ -\chapter{Exercise 17} +\chapter{Exercise 17: Heap And Stack Memory Allocation} +You know about many of the data types that C supports, but +now you need to know how they're stored in memory and how to +get access to greater amounts of memory with \ident{malloc} +and friends. + +\begin{code}{ex17.c} +<< d['code/ex17.c|pyg|l'] >> +\end{code} \section{What You Should See} +\begin{code}{ex17 output} +\begin{lstlisting} +<< d['code/ex17.out|dexy'] >> +\end{lstlisting} +\end{code} \section{How To Break It} diff --git a/ex18.tex b/ex18.tex index 2f1d30e..5cb907c 100644 --- a/ex18.tex +++ b/ex18.tex @@ -1,8 +1,25 @@ -\chapter{Exercise 18} +\chapter{Exercise 18: Pointers To Functions} +Functions in C are actually just pointers to a spot in the +program where some code exists. Just like you've been creating +pointers to structs, strings, and arrays, you can point a +pointer at a function too. The main use for this is to pass +"callbacks" to other functions, or to simulate classes and +objects. In this exercise we'll do some callbacks, and in +the next one we'll make a simple object system. + +\begin{code}{ex18.c} +<< d['code/ex18.c|pyg|l'] >> +\end{code} \section{What You Should See} +\begin{code}{ex18 output} +\begin{lstlisting} +<< d['code/ex18.out|dexy'] >> +\end{lstlisting} +\end{code} + \section{How To Break It} diff --git a/ex19.tex b/ex19.tex index 2fff28b..a523453 100644 --- a/ex19.tex +++ b/ex19.tex @@ -1,4 +1,24 @@ -\chapter{Exercise 19} +\chapter{Exercise 19: A Simple Object System} + +I learned C before I learned Object Oriented Programming, so +it helped me to build an OOP system in C to understand the +basics of what OOP meant. You are probably the kind of person +who learned an OOP language before you learned C, so this kind +of bridge might help you as well. In this exercise, we will +build a simple object system. + + +\begin{code}{ex19.c} +<< d['code/ex19.c|pyg|l'] >> +\end{code} + +\section{What You Should See} + +\begin{code}{ex19 output} +\begin{lstlisting} +<< d['code/ex19.out|dexy'] >> +\end{lstlisting} +\end{code} \section{What You Should See}