3 ms·
Do C compilers for those platforms transparently implement this for your char pointers as GP suggests? I would expect that you would need to do it manually and
by loeg 4y ago
Do C compilers for those platforms transparently implement this for your char pointers as GP suggests? I would expect that you would need to do it manually and that native C pointers would only address the same words as the machine itself.
- mlyle 4y ago> Do C compilers for those platforms transparently implement this for your char pointers as GP suggests? Yes. Lots of little microcontrollers and older big machines have this "feature" and C compilers fix it for you. There are nightmarish microcontrollers with Harvard architectures and standards-compliant C compilers that fix this up all behind the scenes for you. E.g. the 8051 is ubiquitous, and it has a Harvard architecture: there are separate buses/instructions to access program memory and normal data memory. The program memory is only word addressable, and the data memory is byte addressable. So, a "pointer" in many C environments for 8051 says what bus the data is on and stashes in other bits what the byte address is, if applicable. And dereferencing the pointer involves a whole lot of conditional operations. Then there's things like the PDP-10, where there's hardware support for doing fancy things with byte pointers, but the pointers still have a different format than word pointers (e.g. they stash the byte offset in the high bits, not the low bits). The C standards makes relatively few demands upon pointers so that you can do interesting things if necessary for an architecture.
- billpg 4y agoDepends on how helpful the compiler is. This particular compiler had an option to switch off adding in bit shifting code when reading characters and instead set CHAR_BIT to 32, meaning strings would have each character taking up 32 bits of space. (So many zero bits, but already handles emojis.)
- yurish 4y agoI have seen a DSP processor that could address only 16-bit words. And C compiler did not fix it, bytes had 16 bits there.
- loeg 4y agoYeah, this is what I have heard of and was expecting. Sibling comment says it's not universal -- some C compilers for these platforms emulate byte addressing.