D
Dan Pop
In said:If I were designing C from scratch, or even if I were working on the
C89 standard (via time machine), I might propose something like this:
1. Drop the word "byte" altogether.
2. Define a type "storage_unit" (or pick a shorter name if you like)
as the fundamental addressible memory unit. On typical systems, a
storage_unit is an 8-bit unsigned type with no padding bits; on
others, it might be bigger, or even smaller. The mem*() functions
work on arrays of storage_unit. The type "storage_unit*" might even
replace "void*"; malloc() could return a "storage_unit*". Add
implicit conversions to taste (or don't).
3. Define the type "char" independently of the "storage_unit" type.
sizeof(char) needn't be 1. Strings are arrays of char. (I'm glossing
over issues of signed vs. unsigned, and of 8-bit vs. 16-bit vs. 32-bit
character sets. We might eventually want "long char" rather than
"wchar_t".)
4. Since the natural size of a storage_unit might be bigger than the
natural size of a character, we need some way to deal with arrays of
sub-storage_unit elements. Perhaps some arrays could be explicitly
packed, as in Pascal and Ada. Packed structs could eliminate the need
for explicit bit fields. The sizeof operator might need to yield the
size in bits rather than in storage units.
A far more complicated design than the current one. Where are the
redeeming advantages?
Although having the type char practically tied to the architecture's byte
looks like a source of potential problems, those problems consistently
failed to materialise in practice. wchar_t, wide character constants
and string literals are available right there, for anyone needing them.
Dan