On 10/16/2011 12:38 PM, Chuck Guzis wrote:
But--C is implemented on systems without byte
addressing, as
previously noted, where the smallest addressable unit is the word.
Yes, and they do one of several things:
1) implement byte pointers in software, so that a character is smaller
than a word and not hardware addressable
2) use the word as the smallest addressable unit, in which case a
character occupies a full word
3) hybrid - use software-implemented byte pointers for char, and normal
machine pointers for date types that the hardware can address
Note that (3) is possible because C does not require that all pointers
have the same representation. C does not even require that if you take
a char *, cast it to an int *, and then cast it back to a char *, that
you get a valid pointer. In fact, just doing the cast has unpredictable
results and may even crash at the point of the cast, without
dereferencing the resulting pointer.
However, the reverse, taking an int *, casting it to a char *, and then
back to an int *, is required to work. Same with casting an int * to a
void * and back. char * and void * are universal pointers, so if the
implementation uses different pointer representations for different data
types, the char * and void * representations have to be a superset of
the others.
However, while any of those three options can be used for a conforming C
implementation, note that none of them provide a way to address
something smaller than a character, because C defines that all objects
are represented in memory as occupying some exact multiple of the size
of a character, and that a character has to be able to represent at
least 0 to 255 if unsigned, and at leat -127 to +127 if signed.
Could C have been defined with the smallest addressable unit as the
bit? Of course. But it wasn't, and unless you convince the standards
committee to change it, we're stuck with it.