It's a simple question. If to compile the C compiler is needed a C compiler... Maybe directly with assembly code? Perhaps the kernel provides a basic tool for converting C to assembler and create an escalating infrastructure? It's a stupid question also but I'm really interested in how to design an operating system (not me) from 0 to interact with the CPU and memory.
-
2It sounds like you are interested in the topic called "bootstrapping". I suggest you google it and see if that sparks any more specific questions. – Code-Apprentice Feb 05 '13 at 01:38
-
Nowadays you can probably write a cross compiler. – Karthik T Feb 05 '13 at 01:38
-
2The Wikipedia article on [compiler bootstrapping](http://en.wikipedia.org/wiki/Bootstrapping_(compilers)) should be helpful. – Michael Mior Feb 05 '13 at 01:39
-
1+1 for both the idea of a C-compiling kernel module (Linus would love that) and also the notion of "escalating infrastructure". – Kerrek SB Feb 05 '13 at 01:47
-
1Related: [Were the first assemblers written in machine code?](http://programmers.stackexchange.com/q/129123/44705). – Sergey Kalinichenko Feb 05 '13 at 01:50
-
Thanks dasblinkelight, is exactly what I wanted. – user1629569 Feb 05 '13 at 01:52
-
@KerrekSB: Email him so :) – Jack Feb 07 '13 at 03:38
-
possible duplicate of [How was the first C compiler written ?](http://stackoverflow.com/questions/18125490/how-was-the-first-c-compiler-written) – Ciro Santilli OurBigBook.com Sep 06 '15 at 08:27
2 Answers
Bootstrapping
This comes from the phrase, "pulling yourself up by your bootstraps", if you want to look it up. Bootstrapping is a straightforward process, but it is a lot of work.
Write a C compiler in another language.
Write a C compiler in C.
Use the compiler from step #1 to compile the compiler from step #2.
Some other compilers have to be bootstrapped, not just those for C. For example, GHC must be used to compile itself.
Note that bootstrapping is only necessary if both of the following are true:
You are inventing a new language, so there are no existing compilers.
You want to write the compiler in the language you are compiling.
This has nothing to do with operating systems. If you are designing an operating system, you have enough work ahead of you already. If your new operating system does not have a C compiler yet, you can cross-compile the compiler from a different operating system. This is much less work — maybe a few hours or days, instead of months or years.

- 205,541
- 37
- 345
- 415
It sounds like this is a task for tcc
(http://bellard.org/tcc/), the Tiny C Compiler.
It's the smallest C compiler I know of, it can compile a bigger one once you've ported it, and there's numerous guides on how to port it to custom systems.

- 74,081
- 25
- 105
- 166
-
Also tcc is simple enough to "compile" it into x86 assembly/opcodes by hand. It's one of the crazy projects I'd like to do someday: Getting an old punch card reader and punch cards, punching them with a manually "compiled and linked" tcc and hooking up that to the LPC interface of a modern computer with a adaptor made from discrete components, just for the sake of it. – datenwolf Feb 05 '13 at 02:25
-
1