Reply to post: @A Non e-mouse

A Reg-reading techie, a high street bank, some iffy production code – and a financial crash

Peter Gathercole Silver badge

@A Non e-mouse

The shortcuts ++, --, += and -= were designed to allow the code to map on to the instruction set of the PDP-11 (and probably the PDP-7 before this), because there were auto-increment and auto-decrement instruction modes on these processors.

This made it possible for a skilled programmer to write code that would generate fewer instructions (and thus be faster), rather than seeing whether the compiler would spot the possible short-cuts.

Remember, when B (forerunner of both BCPL and C) was written, the machines Ken and Dennis had were only just capable of running a compiler at all, and code optimization was completely out of the question.

The systems were really slow. When I got my first UNIX Version 6 and later version 7 system to look after (a long time after UNIX was first written), compiling the kernel took over 4 hours (and I had relatively fast disks), and I never did get around to recompiling the tool set, just used what came in from the distribution tape. It got to the point where I would touch many of the .o files and the libraries and bits I had not touched just to fool Make into not going the whole hog and compiling everything.

This direct mapping of high level code to machine instructions is why many people used to refer to C as a two-and-a-half generation language, and suitable for writing efficient code for operating systems.

Nowadays, where the systems are so obscenely fast as to make compiling code a relatively trivial operation, adding optimizers into the compiler such that these short cuts are not necessary is a no-brainer, so they could be deprecated, but they're written into the standards, and C has spawned a huge number of C-like languages that have taken much of C syntax into themselves verbatim.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon