3 ms·
> C and C++ are not a very thin abstraction over assembly language We can argue the thinkness (or the thinness) of the abstraction until cows come home, but
by inkyoto 5y ago
> C and C++ are not a very thin abstraction over assembly language
We can argue the thinkness (or the thinness) of the abstraction until cows come home, but
while (*dst++ = *src++) ;
is a direct abstraction over
L1:
movb @(r0)+, @(r1)+
tstb (r0)
bne L1
(assuming «src» and «dst» are both «char *» and addresses are loaded into «r1» and «r0» registers, consequently) in the PDP-11 architecture that C was designed on and for. The instruction sequence is exactly 4x 16 bit words long. As well as
*ptr &= 1;
becoming
and #1, (r0)
and being 2x 16 bit word instruction (assuming «ptr» is an «int *» and is loaded into «r0»). Pointer arithmetic and array design in C as we know them today was highly influenced by the addressing modes existing in the PDP-11 ISA, with many C abstractions having to a direct correspondence to specific sequences of PDP-11 instructions.
C++ is much less of a hardware abstraction, specifically when it comes to the higher level language features.
- pjmlp 5y agoExcept that breaks outside non PDP-11 CPU, where many languages offer the same "low level" capabilities of C. Or 8 bit CPUs like 6502 and Z80 that aren't even able to fully support C.
- inkyoto 5y ago6502 and Z80 had not existed yet when C was begot for the PDP-11 architecture. Yes – historically – C has never been a perfect fit for 8-bit architectures as it had been conceived for a 16-bit architecture. So what? There are C compilers for 68HC08 68HC11 MCU's as well. Yet, C has outlived «many languages offering the same "low level" capabilities of C».
- deleted 5y ago[deleted]
- pjmlp 5y agoThe reasons for its survival cross many axis, it wasn't just for the language alone on its own.
- rswail 5y agoIt really was an elegant instruction set.