Programming Pointers

by Dan Saks , TechOnline India - December 08, 2011

Writing better hardware interfaces may require writing fairly elaborate declarations. It's probably worth the effort.

Writing better hardware interfaces may require writing fairly elaborate declarations. It's probably worth the effort.

About a year and a half ago, I wrote a column explaining some common techniques for representing and manipulating memory-mapped devices in C.1 I followed that with another column explaining an alternative using classes in C++.2 Those initial articles left a lot of details unresolved. Most of the columns I've written since then have been about filling in those missing details.

Nearly all of the techniques I've presented are viable in that real programmers use them in real projects and find the resulting machine code to be adequately fast and compact. Nonetheless, I've suggested that some alternatives are generally better than others, usually on the basis that the better ones yield interfaces that are easier to use correctly and harder to use incorrectly.

Sometimes writing better interfaces requires writing fairly elaborate declarations to model the hardware. Some programmers see such declarations as not worth the bother and opt for something simpler. This month, I'll explain why I don't think that's a winning approach.

A classic approach

C programmers often define symbols for device register addresses as clusters of related macros. For example:

 

To read the entire article click here.

About Author

Comments

blog comments powered by Disqus