The Origins of the "++" and "--" Operators

33 points by wpollock 20 hours ago

TIL you cannot post retraction on a 4 month old comment on HN. I posted an upvoted comment about how these operators were invented in C due to the addressing modes available on PDP-11 computers, in the thread at <https://news.ycombinator.com/item?id=41850017>. Wrong!

Turns out they predate both C and PDP-11 computers. Dennis Ritchie wrote about it in The Development of the C Programming Language, here's a link: <https://web.archive.org/web/20160304194040/http://www.bell-labs.com/usr/dmr/www/chist.html>.

The relevant section is this: "Thompson went a step further by inventing the ++ and -- operators, which increment or decrement; their prefix or postfix position determines whether the alteration occurs before or after noting the value of the operand. They were not in the earliest versions of B, but appeared along the way. People often guess that they 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, however, did have a few `auto-increment' memory cells, with the property that an indirect memory reference through them incremented the cell. This feature probably suggested such operators to Thompson; the generalization to make them both prefix and postfix was his own. Indeed, the auto-increment cells were not used directly in implementation of the operators, and a stronger motivation for the innovation was probably his observation that the translation of ++x was smaller than that of x=x+1."

kps 3 hours ago

Relatedly, the PDP-11 addresses modes are post-increment and pre-decrement in order to allow programming the PDP-11 as if it were a stack machine, with a register pointing at the ‘top’ of the stack (i.e. lowest address). (Reference: Computer Engineering: A DEC View of Hardware Systems Design)

threatofrain 4 hours ago

I've also seen n++ in pedagogical Analysis for the successor function.