Quickie: Configuration Headers

We all know (or at least we should know) that we can use #define to create macros that replace names with values during the preprocessor phase of compilation. Sometimes, it's very important for us to have the ability to change large amounts of code very quickly, because we have a new size limit for

Patterns: Initialize Everything

malloc(): memory corruption When you look at an error message like that, what could possibly lead you to believe that, a hundred lines up, you didn't properly initialize a size variable? After all, all we know is that this malloc() operation could not complete because the memory it should be able to touch is corrupted. Yes,

Patterns: Creation and Destruction Stack

Virtually 100% of all memory leaks are preventable, assuming the programmer knows where to look. In many cases, the leaks occur because a programmer has failed to destroy what he has created, but it can become more complicated than that. Creation Stack: The Order Matters In many cases, we allocate memory as we use it, and

Patterns: Yin and Yang

How many programmers whine that C is dangerous because of memory leaks? How many programmers rely on IDEs because they can't keep track of how many layers of brackets they're using? All of this stress is easily defeated with a little bit of Eastern Philosophy. Yin: Beginnings In the binary unifying force of the cosmos, there are

Patterns: Comment Through History

Programmers are not unlike Dory from Finding Nemo, in that we have a limited memory. It seems like every time we sit down to code, and we are randomly struck by a lightning bolt of inspiration, we immediately lose it when we notice something shiny. That's an extreme example, sure, but programmers do have a

Patterns: Protect the Iterators!

Some patterns are more obvious than others. This is one of the more obvious patterns, but it's violated often enough to deserve enunciation. Iterator Abuse Just about every program out there uses an iterator for one reason or another. Without them, we can't build for loops, and more than a few while loops require iterators as

Patterns: “Classes” in C

Encapsulation is a key aspect of the Object Oriented Programming model, and for good reason. We have an easier time grasping units which do one thing than hundreds of independent operations and objects that can do a number of things. While C does not contain the class descriptor found in C++ or Java, we