Sujet : Re: technology discussion → does the world need a "new" C ?
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 10. Jul 2024, 08:16:18
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6lcg3$1qhmn$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla Thunderbird
On 7/9/24 20:57, Lawrence D'Oliveiro wrote:
On Sat, 6 Jul 2024 21:34:29 -0400, James Kuyper wrote:
On many platforms, if _Alignof(type) is less than the word size, then a
C pointer to that type is implemented as the combination of the machine
address of the correct word, combined with an offset within that word of
the first byte of that object.
Which is a terrific idea, except it cannot be carried to its logical
conclusion (addressing of arbitrarily-aligned dynamically-defined
bitfields) because of the requirement in the C spec that the size of a
“byte” be at least 8 bits.
I will grant you that I failed to mention the fact that this is a
feasible way of implementing C only on platforms with a word size of 16
bits or longer. I assumed that would be obvious - I apologize for not
anticipating that it might not be.
On platforms where the word size is smaller than 8 bits, the opposite
strategy applies: instead of storing multiple bytes in a word, an
implementation would have to use multiple words to store a byte.
I know that there's a fair number of implementations that use the first
approach, I have no idea whether there are any that use the second
approach. It should be feasible, but it would probably be more trouble
than it's worth. The key point is that the addressable unit in C can be
emulated - it needn't bear any particularly close relationship to the
hardware addressable unit.