📅 2005-May-04 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ cpp, types ⬩ 📚 Archive
A colleague informed me today that my name had appeared in the April 2005 issue of the Embedded Systems Programming magazine. Back in December 2004, I had commented to Dan Saks about his article More ways to map memory on the usage of the available C fixed width integer types. We had an email discussion on it and I forgot all about it. I had blogged earlier about these types.
In his latest article Sizing and aligning device registers he mentions that email conversation. I know this is not anything significant, but this is the first time my name has appeared in a deadwood tech magazine! 😊
Ashwin N (email@example.com) suggested yet another way to define the special_register type:
If you want to use an unsigned four-byte word, shouldn’t you be doing:This should work with all modern standard C compilers/libraries.
#include /* ... */ typedef uint32_t volatile special_register;
uint32_tis an alias for some unsigned integer type that occupies exactly 32 bits. It’s one of many possible exact-width unsigned integer types with names of the form
Nis a decimal integer representing the number of bits the type occupies. Other common exact-width unsigned types are
uint16_t. For each type
uintN_t, there’s a corresponding type
intN_tfor a signed integer that occupies exactly
Nbits and has two’s complement representation.
I have been reluctant to useAgain, using a typedef such as
<stdint.h>. It’s available in C99, but not in earlier C dialects nor in Standard C++. However, it’s becoming increasingly available in C++ compilers, and likely to make it into the C++ Standard someday. Moreover, as Michael Barr observed, if the header isn’t available with your compiler, you can implement it yourself without much fuss. I plan to start using these types more in my work.
special_registermakes the exact choice of the integer type much less important. However, I’m starting to think that
uint32_tis the best type to use in defining the special_register type.