Why does the C programming language (and other C-like languages) have pre and post operators?

This is an interesting question that has a common answer that turns out to be a myth/historically incorrect.

TLDR; the definitive answer to this question comes from Dennis Ritchie himself, developer of the C language in his article “The Development of the C Language” – http://www.bell-labs.com/usr/dmr/www/chist.html 

“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.

From http://www.bell-labs.com/usr/dmr/www/chist.html

The common answer which turns out to be incorrect is (paraphrasing) “C has pre and post operators because C was developed on the PDP-11 and this machine had pre and post CPU instructions, the implementation of ++ and — in C used these machine instructions”.

The explanation from Ritchie that corrects this misconception:

“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”

From: http://www.bell-labs.com/usr/dmr/www/chist.html

An interesting piece of computing history.

awk basics

I’ve tinkered with awk and sed for quick one off tasks before in the past but I always have to go back and check the syntax for awk as it’s one of those things I use only once in a while.

Some quick notes for reference for later:

  • awk splits records in an input file by default by white space chars
  • uses $0 to refer to a whole line, and $1 … $n to refer to each matching token on a line
  • to split using column delimiters other than whitespace use -F

Examples:

Example file – example1.txt:

aaa bbb ccc
ddd eee fff

$ awk {'print $1'} example1.txt

Will print the first matching column:

aaa
ddd

If file has other column delimiters use -F to specify the delimiter, for example, example2.txt:

aaa,bbb,ccc
ddd,eee,fff

$ awk -F , {'print $2'} example2.txt

Will match column 2:

bbb
eee

More info on awk here.

For no particular reason, a Sparc workstation is on it’s way

I was shopping for one of these on ebay:

https://en.wikipedia.org/wiki/SPARCstation_20

By Caroline Ford – Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=1504020

But then got caught up on the idea that an Ultra 5 with IDE disk support might be a better idea:

https://en.wikipedia.org/wiki/Ultra_5/10

By Liftarn – https://commons.wikimedia.org/w/index.php?curid=2094130

After a lively discussion in the Facebook Vintage Unix Machines group about the pros and cons of older Sparcstations, Ultra 1 and 2, vs Ultra 5/10, I decided to shop for an Ultra 1 or 2. I made an offer on one but didn’t get it. And then I decided to go for an Ultra 60 since it was cheaper than anything else I could find, although in a unknown working condition, other than ‘it powers on’. So when it turns up it will be a learning experience to see if it’s actually in working condition or not.

I believe from photos from the ebay listing that there’s a SunPCI card in there, so that will be interesting to play with, and also the Creator 3D graphics card.

On my shopping list of needed parts:

  • a Sun Type 5 keyboard and mouse (with Sun mini DIN connector)
  • a 13W3 video to VGA adapter
  • an SCA SCSI disk
  • possible future purchase, a SCSI2SD adapter