Progress on my C pointers book

Thomas Mailund
2 min readOct 16, 2020

I was asked to write a short introductory book on using pointers in C by Apress, and we agreed on around 200 pages because that was as much as I thought I could say on the topic. If I had stuck to my original plan, and focused on using pointers to implement recursive data structures, that would probably be correct. But once I got started, more and more it dawned on me how much there really is to pointers in C.

I am now done with the first three chapters, except that there turned out to be seven of them after I had some discussions with friends and there got a little “language lawyering” in there. Those chapters handle arrays and strings. I have also drafted a chapter on dynamic memory management — well, allocation and free’ing. It is not really that I have a lot to say there, but I wanted a few useful examples to show the concepts. I have dynamic arrays and gapped buffers, for example. And when I am more careful about checking for size overflows and such, the content grows. The code doesn’t grow that much, with appropriate functions and macros, but the explanations do.

So now I am approaching 200% of the page count we agreed on (it is okay, I have permission for that now), and I am only getting started on recursive data structures. There will be less of those now because I don’t want a tome of a book, but I will have a little. Maybe Future Thomas will write about it some other day.

I think I can still manage allocation pools in one chapter. There isn’t frightfully much to them, even if I have to handle alignment correctly for a generic pool (something I hadn’t thought about when I made the book plan). Reference counting shouldn’t take up more than one chapter either, although I had some examples in mind that would make it grow beyond that. If I control myself and do not include them, then things are on track. Function pointers might expend to two chapters, though, one on high-order function and one on polymorphism. I cannot not mention code generation, of course, but it won’t be more than one example, I promise.

I am looking forward to implementing the examples for the more advanced topics. And I am back on schedule for the deadlines I have, even if the book is growing far beyond the original plan. So things are going well. But now it is time to call it a day and start the weekend, because I have some IKEA stuff to assemble, and starting when you are in a good mood is best. It reduces the chance of ending up in homicidal rage slightly.

--

--

Thomas Mailund

Associate professor in bioinformatics and author of a bunch of text books