It’s not uncommon that we find ourselves repeatedly editing our code and recompiling, just to change the value of a constant. In C, though, we can skip the step where we edit the source file to change the constant’s value. Instead, we can use a combination of the #define and #ifndef preprocessor directives to change its value directly on the command line at compile-time.
Author: Ryan Vogt
Exiting on malloc(3) Failure
To the annoyance of many students learning C programming, allocating memory by calling malloc(3) can fail. When it does, malloc(3) will return NULL. But, what should our program do when a call to malloc(3) fails? The question that today’s blog post explores is: when is it okay for our program to exit(3) — that is, simply terminate — because of a memory-allocation failure?
Better printf(3) Debugging in C
In today’s blog post, we’ll look at one way to improve printf(3) and fprintf(3) debugging in C. Namely, let’s make it so our printf(3) debugging outputs include the name of the source code file, the function name, and the line number where the output happens. Debugging with printf(3) is fast and easy, and it’s not going anywhere; so, let’s just make its output more useful.
Better println() Debugging in Java
In today’s blog post, we’ll look at one way to improve System.out.println() debugging in Java. Namely, let’s make it so our println() debugging outputs include the name of the source code file, the method name, and the line number where the output happens. Debugging with println() is fast and easy, and it’s not going anywhere; so, let’s just make its output more useful.
The Big Three in Java, Part Four: equals(Object) in Hierarchies
In the final entry in a series of four blog posts about the “big three” methods in Java, we return to the Object.equals(Object) method. Specifically, we discuss how to maintain the symmetry and transitivity properties of the method in class hierarchies. We answer the question: when do we use instanceof, and when do we check for class equality instead?