4 ms·
from the stackoverflow topic titled: "What are the historical reasons C languages have pre-increments and post-increments?": https://stackoverflow.com/questio
by giardini 6y ago
from the stackoverflow topic titled:
"What are the historical reasons C languages have pre-increments and post-increments?":
https://stackoverflow.com/questions/30429753/what-are-the-historical-reasons-c-languages-have-pre-increments-and-post-increme https://stackoverflow.com/questions/30429753/what-are-the-hi...
A quote from that topic:
>'Ritchie, The Development of the C Language:
"People often guess that they [ED. the increment and decrement operators] were created to use the auto-increment and auto-decrement address modes provided by the DEC PDP-11 on which C and Unix first became popular. This is historically impossible, since there was no PDP-11 when B was developed." The PDP-7 seems to have some features that might have played a role, albeit I don't think it's entirely clear from the document that they were the main reason for the existence of both prefix and postfix ++'<
- hazeii 6y agoThat's interesting, as I'd assumed the BCPL/B/C progression happened alongside the PDP-7 to PDP-11 progression with the PDP-11 being the design that regularised things. The full set of addressing modes uses 3 bits, thus 8 addressing modes. Using these addressing modes on the program counter (R7) gave a lot of flexibility and was how constants and memory were loaded and stored. It might sound complex but in practice was incredibly easy:- mov #141,@#177566 ; Output 'a' to the terminal That's a "MOV (PC)++,@(PC)++" instruction that loads the next word from memory (octal 141) and increments the PC and stores in the address given by the next word (after the constant, as the PC has just been auto-incremented) and finally autoincrements the PC again to leave it pointing to the next instruction. The layout in memory would thus be:- 12737 # Instruction: MOV (PC)++,@(PC)++ 00141 # ASCII 'a' 177566 # Address of terminal outer buffer Given these games using the PC to address data and memory, PDP-11 programmers had little difficulty when it came to understanding C pointers.