News for hackers. Stuff that matters.
Re:Dennis Ritchie's first C compiler on Github by habosa on Tuesday May 21, 2013 @11:35PM (#5748718)
Is this written in C? If so, what compiled this? Sorry for the noob question, I'm just a little lost.
Re:Dennis Ritchie's first C compiler on Github by tcas on Tuesday May 21, 2013 @11:41PM (#5748740)
Looks like a very early dialect. C assumes everything is an int unless specified otherwise. You can declare parameter types after the function name. So:

  init(s, t)
  char s[]; {
would be equivalent to:

  int init(char s[], int t) {
This still works with modern compilers.

I'd be interested if anyone has any more info about this:

  waste()		/* waste space */
  {
  	waste(waste(waste),waste(waste),waste(waste));
  	waste(waste(waste),waste(waste),waste(waste));
  	waste(waste(waste),waste(waste),waste(waste));
  	waste(waste(waste),waste(waste),waste(waste));
  	waste(waste(waste),waste(waste),waste(waste));
  	waste(waste(waste),waste(waste),waste(waste));
  	waste(waste(waste),waste(waste),waste(waste));
  	waste(waste(waste),waste(waste),waste(waste));
  }
Found in last1120c/c10.c
Re:Dennis Ritchie's first C compiler on Github by cwzwarich on Tuesday May 21, 2013 @11:47PM (#5748762)
From the linked description (http://www.cs.bell-labs.com/who/dmr/primevalC.html):

A second, less noticeable, but astonishing peculiarity is the space allocation: temporary storage is allocated that deliberately overwrites the beginning of the program, smashing its initialization code to save space. The two compilers differ in the details in how they cope with this. In the earlier one, the start is found by naming a function; in the later, the start is simply taken to be 0. This indicates that the first compiler was written before we had a machine with memory mapping, so the origin of the program was not at location 0, whereas by the time of the second, we had a PDP-11 that did provide mapping. (See the Unix History paper). In one of the files (prestruct-c/c10.c) the kludgery is especially evident.

Re:Dennis Ritchie's first C compiler on Github by tcas on Wednesday May 22, 2013 @12:10AM (#5748833)
Doh, I completely glossed over the readme and went straight to the code. That makes sense -- Thanks!

Cool to think that that waste function can still compile with todays compilers. A quick disassembly it seems to take up 751 bytes compiled on x64 using clang on O0.

Re:Dennis Ritchie's first C compiler on Github by enf on Wednesday May 22, 2013 @12:10AM (#5748839)
That was the standard way of declaring parameter types until ANSI C in 1989. C actually copied the current style back from C++.
Re:Dennis Ritchie's first C compiler on Github by _kst_ on Wednesday May 22, 2013 @08:39PM (#5754688)
ANSI C didn't drop old-style (non-prototype) function declarations and definitions -- nor did C99 or C11. They've been officially obsolescent since 1989, but they're still fully supported by any conforming compiler.
Re:Dennis Ritchie's first C compiler on Github by Mr_T_ on Wednesday May 22, 2013 @04:53AM (#5749568)
> Looks like a very early dialect. C assumes everything is an int unless specified otherwise.

It looks beautiful, almost like a scripting language. No monster type signatures like

    const std::foo_bar<boost::blah_ptr<const xyz::bar::Bar&, baz::Baz>>&
Re:Dennis Ritchie's first C compiler on Github by chiph on Wednesday May 22, 2013 @08:34AM (#5750297)
I think the modem carrier dropped on your last line. Can you resend?
Re:Dennis Ritchie's first C compiler on Github by ghshephard on Tuesday May 21, 2013 @11:42PM (#5748743)
From the link on GitHub:

http://cm.bell-labs.com/cm/cs/who/dmr/primevalC.html

Which led me to here:

http://cm.bell-labs.com/cm/cs/who/dmr/chist.html

Where, if you take the time, you will find a wonderful story, upon completing, you will probably know more about the early embryonic history of C then 95% of your peers.

(Spoiler - We start with BCPL, then Move to B - it's left as an exercise to determine how we originally compiled BCPL)

Re:Dennis Ritchie's first C compiler on Github by mseepgood on Wednesday May 22, 2013 @12:32AM (#5748894)
> (Spoiler - We start with BCPL, then Move to B - it's left as an exercise to determine how we originally compiled BCPL)

The first version of Go started with B: http://code.google.com/p/go/source/detail?r=f6182e5abf5e

The second revision was converted to C: http://code.google.com/p/go/source/detail?name=f6182e5abf5e&...

The third to Draft-Proposed ANSI C: http://code.google.com/p/go/source/detail?name=f6182e5abf5e&...

And the fourth to ANSI C: http://code.google.com/p/go/source/detail?name=f6182e5abf5e&...

Re:Dennis Ritchie's first C compiler on Github by chubot on Wednesday May 22, 2013 @02:41AM (#5749259)
Uh these commits seem interesting, but I don't quite understand the context. What's macho and what is its relation to go? Are the dates way off or is it an import of older history?
Re:Dennis Ritchie's first C compiler on Github by glurgh on Wednesday May 22, 2013 @03:38AM (#5749389)
Your leg is being pulled, a little. Mach-o is the mach object file format, Brian Kernighan's C 'hello world' program is being used as source for, I think, a test. It's checked into the go tree with version history all the way back to its primordial source.
Re:Dennis Ritchie's first C compiler on Github by lifthrasiir on Wednesday May 22, 2013 @12:45AM (#5748931)
They definitely messed up with a conversion from Subversion to Mercurial. ;)
Re:Dennis Ritchie's first C compiler on Github by hkmurakami on Tuesday May 21, 2013 @11:51PM (#5748779)
coupled with user:rmrfrmrf's pseudo-religious post praising the code, I read the second url as "christ" :P

Oh how our minds play tricks on us!

Re:Dennis Ritchie's first C compiler on Github by btilly on Tuesday May 21, 2013 @11:45PM (#5748751)
Your question is answered at length in http://plan9.bell-labs.com/who/dmr/chist.html. But it is common to write compilers some subset of the language that you want to compile, see http://en.wikipedia.org/wiki/Bootstrapping_(compilers).
Re:Dennis Ritchie's first C compiler on Github by lanna on Tuesday May 21, 2013 @11:54PM (#5748794)
A compiler has to do a lot more than parse a source file and translate it to target code: error checking and reporting, optimization, etc.

To compile a C compiler, you don't need a full-blown C compiler. For instance, I bet floats and doubles are not used. Therefore, you can write a barebones proto-C compiler in whatever language you have available and use it to bootstrap your compiler. Rinse and repeat.

Re:Dennis Ritchie's first C compiler on Github by jshou on Tuesday May 21, 2013 @11:38PM (#5748736)
Re:Dennis Ritchie's first C compiler on Github by habosa on Tuesday May 21, 2013 @11:45PM (#5748752)
I understand bootstrapping, but at some point there has to exist some outside compiler in another language or a hand-compiled version of this otherwise the chicken and egg chain never ends.
Re:Dennis Ritchie's first C compiler on Github by sytelus on Wednesday May 22, 2013 @12:42AM (#5748918)
The very first compilers were tediously written in assembly. Bill Gates wrote his first version of Basic in assembly. I believe all early Fortran compilers were written in direct machine code through punch cards! Coding in assembly is not all that bad :). Once you got some compiler going, you can write more complex compiler with it and keep adding more syntactic sugar :).
Re:Dennis Ritchie's first C compiler on Github by GnarfGnarf on Wednesday May 22, 2013 @12:44PM (#5752042)
Coding in Assembly was a gas! I wrote applications in IBM BAL in the 70's. G/L, Payroll, Inventory. We did it in part because we had so little memory (typically 64K to 131K), we had to squeeze every drop we could out of available memory.

I worked on Univac 9400s. We received the O/S in source code form (Assembly) on tape. We ran it through a parametizer (PROC), compiled the resulting source, and that's what the customer ran with.

You haven't lived until you've stepped through your code one instruction at a time, displaying op codes and raw binary data on the maintenance panel lights.

Re:Dennis Ritchie's first C compiler on Github by coliveira on Wednesday May 22, 2013 @12:30AM (#5748891)
You can use any language available in the machine to create the first, most basic compiler. You can also use a cross-compiler if a compiler for the language already exists for another machine. If all else fails, you can write the proto-compiler in assembly.
Re:Dennis Ritchie's first C compiler on Github by guelo on Wednesday May 22, 2013 @01:41AM (#5749108)
The mysterious true origins of bootstrapping compilers.
Re:Dennis Ritchie's first C compiler on Github by kibibu on Tuesday May 21, 2013 @11:41PM (#5748741)
Presumably the first step on the road to a self-compiling C compiler was written in B.
Re:Dennis Ritchie's first C compiler on Github by Jach on Tuesday May 21, 2013 @11:52PM (#5748780)
One might write a compiler from language X to language Y first in assembly, then when that works, write a new compiler from language X to language Y in language X itself and use the previous compiler to compile it. Presumably they already had a C compiler that they used to get this one compiled, then it can compile itself afterwards.