The “const” keyword in the C programming language, when applied to pointers, can be quite confusing to read. How do you read a variable declaration like “const char *const *const p”? This blog post explains how to read these declarations, and demonstrates the technique of reading them from right to left.
Tag: C
Allocating Arrays with calloc(3) Instead of malloc(3)
In this blog post, we’ll explore dynamically allocating memory for an array in C. In particular, we’ll see why the idiom of malloc(3)’ing memory equal to the number of elements in an array multiplied by the size of each element should be avoided, and why calloc(3) should be used instead.
Aborting on Programming Errors
Programming errors can be as small and subtle as an off-by-one error in a loop, or as large as a flaw in the implementation or design of an important algorithm. What should our code do when it runs into this type of error? In most cases, we shouldn’t be afraid just to make our program abort.
Wrapping Multiline Macros in C With Do/While
This blog post describes logical errors that can occur with multiline macros in C programming, and demonstrates how to resolve them directly in the definition of the macro itself. After reading this post, you should understand why wrapping multiline C macros with a “do/while” statement is a best practice to avoid these logical errors.