5 ms·
If the first C compiler was written in C... how could it be first C compiler? How could you compile the first C compiler?
by 29athrowaway 6y ago
If the first C compiler was written in C... how could it be first C compiler? How could you compile the first C compiler?
- dvt 6y agoThe first (or proto) C compiler was written in B†[1] (called NB, or New B). This is the first C compiler written in C. † Or maybe some variant of BCPL -- I'm not exactly sure how functionally different the two were. [1] https://www.bell-labs.com/usr/dmr/www/chist.html https://www.bell-labs.com/usr/dmr/www/chist.html
- deleted 6y ago[deleted]
- Nicksil 6y agoBootstrapping https://en.wikipedia.org/wiki/Bootstrapping_(compilers) https://en.wikipedia.org/wiki/Bootstrapping_(compilers)
- Blikkentrekker 6y agoIf it could bootstrap itself, then there would be no need to port it to GCC. From how I read it, it is not capable of bootstrapping itself, and an earlier C compiler in BCPL existed, this is the first C compiler written in C itself.
- dmitrygr 6y agothis port is [optionally] a cross compiler - it will run on x86/arm/whatever and produce pdp11 assembly on an actual pdp11 it CAN bootstrap
- pabs3 6y agohttps://bootstrappable.org/ https://bootstrappable.org/
- johan_felisaz 6y agoProbably out of topic, but are there real examples of compiler attacks due to bootstrapping ? I did not hear about them before reading the scifi classic Accelerando by C. Stross
- goldsteinq 6y agoOh, the thing with bootstrapping attacks is you never know are there any real examples. I recommend this[0] paper by Ken Thompson dated 1984 and still relevant. [0]: https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_ReflectionsonTrustingTrust.pdf https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_Ref...
- ForOldHack 6y agoBrilliant. I was going to post this but you posted it first, I read this while learning to program in C, and then looked at my compiler with extreme suspicion.
- onei 6y agoThe very first B compiler was written in BCPL by Ken Thompson. B later became self-hosting, i.e. the BCPL compiler compiled the B compiler, but this had another set of challenges due to the extreme memory constraints. It was an iterative process where a new feature was added such that it pushed the memory limit and then the compiler was rewritten to use the new feature to bring the memory usage down. C was heavily inspired by B and I suspect written in B aswell. Alternatively, BCPL was extremely portable as it compiled to OCode (what we'd recognise today as bytecode) so that might have been another option. The assignment operators of =+ are straight from B and later changed to += due to Dennis Ritchie's personal taste.
- aap_ 6y agoThe first B compiler was actually written in TMG, and once it was bootstrapped that way in B itself. BCPL was only the inspiration for the language.
- sramsay 6y agoWow, TMG was a new one for me. From the Wiki article on it: "Douglas McIlroy ported TMG to an early version of Unix. According to Ken Thompson, McIlroy wrote TMG in TMG on a piece of paper and "decided to give his piece of paper his piece of paper," hand-compiling assembly language that he entered and assembled on Thompson's Unix system running on PDP-7." We are not worthy, friends. We are not worthy.
- kragen 6y agoI did pretty much the same thing with https://github.com/kragen/peg-bootstrap/blob/master/peg.md https://github.com/kragen/peg-bootstrap/blob/master/peg.md, although admittedly hand-compiling to JS was noticeably less work than hand-compiling to assembly language would have taken. My friend Dave did something similar with Val Schorre's META-II: https://queue.acm.org/detail.cfm?id=2724586 https://queue.acm.org/detail.cfm?id=2724586 (missing the figures for some reason, so see:) doi:10.1145/2697401
- ForOldHack 6y ago
- IncRnd 6y agoIt was bootstrapped. For compilers, it is sort of "a thing" to finally bootstrap your new language compiler in your new language.
- ForOldHack 6y agoThe question of if the first C compiler was written in C, how could it be the first C Compiler? Because to be the first, it has to be bootstrapped in an intermediate host language… You have to get a parser running, then the syntax, then the etc… etc… ( immense plug of the Ahl book here…) To be the first complier in a language, as was pointed out, long before I was born, the compiler has to compile itself, so before it could compile itself, it had to have other language processing programs creating the parsing, the syntax, the etc… Porting it to GCC just means that they could compile it with GCC, the big test is to get it to compile itself, on what ever platform that is the target platform, because finally, if it cannot generate object code/machine language in the target machine’s binary, then its not really ported. Later on, UNIX came with tools to build compilers with, YACC and LEX. If they got it to produce PDP-7 Code, its not really much of a port, really.
- 29athrowaway 6y agoIt was a rhetorical question. It wasn't the first C compiler, it was the first self-hosted C compiler, which is different.