To say it’s been some time since I last posted is an understatement! I won’t bore you with the details other than to note that sometimes there just aren’t enough hours in a day. Anyway, today’s post is about a stylistic issue I’ve noticed in just about all code I’ve ever looked at. Unless you […]
Category: General C issues
Replacing nested switches with multi-dimensional arrays of pointers to functions
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, […]
What’s in your main() header?
One of the consequences of being in the consulting business is that I get to look at a lot of code written by other people. Usually it is necessary for me to get up to speed on the code as quickly as possible, and so to this end, one of the first things I do […]
Real world variables
Part of what makes embedded systems fun for me is that they normally interact with the physical world. The physical world contains real parameters which we measure using transducers, signal conditioning circuits and so on, such that ultimately we end up with a variable in our embedded code that purports to represent this real world […]
All variables are equal, but some are more equal than others
With all due apologies to George Orwell for the title, I thought I’d offer a little tidbit on the practice of the following construct: uint8_t a,b,c,d; a = b = c = d = 0; This code declares four variables (a,b,c,d) and sets them all equal to 0. The question is, is this a good, […]
What does 0x47u mean anyway?
In the last couple of years I have had a large number of folks end up on this blog as a result of search terms such as “what does 0X47u mean?” In an effort to make their visit more productive, I’ll explain and also offer some thoughts on the topic. Back in the mists of […]
The Crap Code Conundrum
Listed below are three statements. Based on my nearly thirty years in the embedded space I can confidently state that: One I have never heard stated. Another I have rarely heard stated, and the third I hear a lot. Here they are in order: I write crap code. You know so-and-so. (S)he writes really good […]
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 […]
The absolute truth about abs()
One of the more depressing things about the C language is how often the results of various operations are undefined. A prime example of this is the abs() function that I’m fairly sure is liberally dispersed throughout your code (it is through mine). The undefined operation of the abs() function comes about if you have […]
Simplify, then add lightness
As 2011 draws to a close I have reason to be thinking about things automotive. As part of my musings, I was reminded of the famous mantra espoused by the late Colin Chapman of Lotus Cars – ‘Simplify, then add lightness’. I have always liked this aphorism for its idea of ‘adding lightness’ rather than […]