This paper discusses the basics of hardware manipulation using C and C++. It focuses on the common idioms for controlling devices that you can write in Standard C or Standard C++.

Both C and C++ provide the following features that aid embedded programming:

  • bitwise operators and bitfields for packing data and manipulating individual bits in
    hardware registers

  • the const qualifier for identifying ROMable data
  • the volatile qualifier for identifying objects, such as memory-mapped device registers,
    that may change due to events outside a program’s control

C++ does not add any features specifically for embedded programming, but classes can
be extremely helpful in hiding messy hardware details behind cleaner interfaces.