It’s been way too long since I’ve written a blog post. To those kind souls that have written to inquire if I’m still alive and kicking – thank you. The bottom line is that there simply aren’t enough hours in the day. Anyway in an effort to get back in the groove so to speak, […]
Category: Effective C/C++
Optimizing for the CPU / compiler
It is well known that standard C language features map horribly on to the architecture of many processors. While the mapping is obvious and appalling for some processors (low end PICs, 8051 spring to mind), it’s still not necessarily great at the 32 bit end of the spectrum where processors without floating point units can […]
Effective C Tip #9 – use #warning
This is the ninth in a series of tips on writing effective C. Way back in 1999 I wrote an article for Embedded Systems Programming concerning the #error directive. If you aren’t particularly familiar with #error, then I suggest you read the article. While the #error directive has remained one of my most popular tools, I have become an […]
Configuring hardware – part 3
This is the final part in a series on configuring the hardware peripherals in a microcontroller. In the first part I talked about how to set / clear bits in a configuration register, and in the second part I talked about putting together the basic framework for the driver. When I finished part 2, we had got […]
Configuring hardware – part 2.
This is the second in a series on configuring the hardware peripherals in a microcontroller. In the first part I talked about how to set / clear bits in a configuration register. Now while setting bits is an essential part of the problem, it is by no means the most difficult task. Instead the real problem is […]
Effective C Tip #8 – Structure Comparison
This is the eighth in a series of tips on writing effective C. Today’s topic concerns how best to compare two structures (naturally of the same type) for equality. The conventional wisdom is that the only safe way to do this is by explicit member by member comparison, and that one should avoid doing a straight bit […]
Effective C Tip #7 – Use strongly typed function parameters
This is the seventh in a series of tips on writing effective C. Today’s topic concerns function parameters, and more to the point, how you should choose them in order to make your code considerably more resilient to parameter passing errors. What do I mean by parameter passing errors? Well consider a function that is intended to […]
Effective C Tip #6 – Creating a flags variable
This is the sixth in a series of tips on writing effective C. Today I’m going to address the topic of creating what I call a flags variable. A flags variable is nothing more than an integral type that I wish to treat as an array of bits, where each bit represents a flag or boolean value. […]
Effective C Tip #5 – Use pre-masking rather than post-masking
This is the fifth in a series of tips on writing what I call effective C. Today I’d like to offer a simple hint that can potentially make your buffer manipulation code a little more robust at essentially zero cost. I’d actually demonstrated the technique in this posting, but had not really emphasized its value. Consider, for example, a […]
Effective C Tip #4 – Prototyping static functions
This is the fourth in a series of tips on writing effective C. I have previously talked about the benefits of static functions. Today I’m addressing where to place static functions in a module. This posting is motivated by the fact that I’ve recently spent a considerable amount of time wading through code that locates its static functions at […]