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

Quickie: Why Java Has No Headers

Ever noticed that Java has no header files? Instead, Java uses one file to store each public class and its functions. Why would they require each class to have its own file? It's a question of simplicity for the Java designers. The Java precompiler (as it were) builds class symbols using the file names, which

Quick Tips for Making Headers

In the world of C/C++, we use headers extensively. The basic rule is that C/CPP files contain code that becomes binaries, and H files contain the interfaces that allow us to reference them in other C files. Any program more complex than a calculator will likely contain multiple C files that are combined into

Tools vs APIs

If you are making a product that will employ unique self-signed certificates and private keys, how would you go about it? The two basic techniques are: Run a tool like OpenSSL's cert tool, either at user discretion or through a script Build the certificate generator directly into your program Let's take a quick look at what each

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,

Debugging Pro-Tip: Malloc() Errors

On Friday, I spent a number of hours trying to run down an error in a fairly substantial piece of code. All I really knew was that I kept getting an error that said something like: *** glibc detected *** ./my_program: malloc(): memory corruption: 0x0000000002296980 *** When I pushed this piece of code through gdb, I

Cleaning up – Comment out old code

If you've spent any appreciable time in the programming world, you've probably reorganized your code any number of times. When I'm writing code, I usually slap things out as I think of them, resulting in code that (while easy enough to read) defies the principle of unity. You'll see me write things like this: [c] int

Patterns: Shielding Inputs with const

One of the key worries I have heard from those ill-informed OOP programmers is that C cannot protect inputs you pass into functions. They use private fields and retrieval functions to ensure that the stored value is protected from unwanted modification. However, this concern is addressed by C's const keyword. Taking a const value There are times

Patterns: The If-Else Error Chain

In languages like Java, we have a standardized error-handling paradigm in the try-catch expression. Effectively, this hands all error-handling off to the computer, which monitors all code in the try loop for any and every kind of possible error. While we are able to restrict the range of errors in many cases, the fact