Integer Types

Randall Maas 7/9/2011 3:58:06 PM

This is mostly an update to the previous post wherein I described integer types, especially those with specific sizes.

Since then I found an excellent article titled "Everything you ever wanted to know about C types" by Peter Seebach:

Short version:

  1. Not all integer types are available. This is not surprising. Mr Seebach helps outline which macros to check for to see if they are.
  2. Types for the machines preferred integer types. (This is usually called word size, but I'm cautious with that. First, different units in the processor often have different word sizes. Second, many people used to Intel processors think of "WORD" as 16 bits, "DWORD" as 32 bits... and the modern Intel processor has a word size of 32 or 64 bits...)
  3. A mechanism to find the largest available integer size

And a whole slew of other info (worth a topic for another time) including pointers:

  1. Did you know that many different pointers "values" can be equal to a null pointer - not just (void*) 0? These are null pointers..
  2. Did you know that its possible for a pointer, after a free()?
  3. Base-2 isn't really required for integers - you could use gray code, for instance - but everyone assumes base-2 for integers...
  4. That many types define "trap" values, that when used have undefined behaviour (and may cause some sort of fault)? (Null pointers and divide by zero aren't part a structure definition now, I supposed)