Sujet : Re: technology discussion → does the world need a "new" C ?
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 07. Jul 2024, 02:34:29
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6crb5$1gpa$1@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : Mozilla Thunderbird
On 7/6/24 03:25, Lawrence D'Oliveiro wrote:
On Fri, 05 Jul 2024 19:00:58 -0700, Keith Thompson wrote:
C assumes byte addressibility, but it doesn't assume that bytes are 8
bits.
>
The PDP-10 had 36-bit words and could operate on bit fields of any size
from 1 to 36 bits.
But it couldn’t address them.
It doesn't matter whether there's hardware support for addressing bytes
- byte addressing can be emulated in software on any platform
sufficiently powerful to implement C's bitwise operators. To read a byte
on a word-addressed machine where the word size is multiple bytes, just
read in the word, then extract the bits that represent that particular
byte. To write a byte on such a machine, read in the current contents of
that word, replace the bits that represent that byte with their new
values, and write the entire word back to memory.
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. The existence of real world
implementations that did this is the main reason that the C standard
does not require that all pointers have the same representation.
This may be inefficient, maybe sufficiently so to be a reason for
avoiding using C on such a platform, but it doesn't (and hasn't) prevent
the existence of a fully conforming implementation of C on that platform.