2

Possible Duplicate:
How are gcc/g++ bootstrapped?

I would like to know how gcc is compiled as we all know it is written in C.

Did they used some other compiler to come up with gcc?

If so, can I use the same compile to compile my C program?

Community
  • 1
  • 1
Viswesn
  • 4,674
  • 2
  • 28
  • 45
  • glibc is just a library. It's written in C, and of course you can compile it in C. – Kerrek SB Aug 03 '12 at 15:17
  • I think he means gcc, not glibc. – Bill Lynch Aug 03 '12 at 15:18
  • I mean gcc, sorry for that, I will change the heading now. – Viswesn Aug 03 '12 at 15:20
  • By the way, glibc works too. I'm assuming you're talking about libc with gcc, which is called "glibc". –  Aug 03 '12 at 15:21
  • Possibly related [How are gcc/g++ bootstrapped?](http://stackoverflow.com/q/9429491) I can't quite work out what the question is. – Flexo Aug 03 '12 at 15:22
  • That's what I'm thinking too, possibly related to ^ –  Aug 03 '12 at 15:24
  • Also, read [The Development of the C Language](http://cm.bell-labs.com/who/dmr/chist.html). – jxh Aug 03 '12 at 15:39
  • @Viswesn how old are you, man? :) – holex Aug 03 '12 at 15:40
  • @holex Does my age matter here ? :) – Viswesn Aug 03 '12 at 15:42
  • @Viswesn no, of course not, just you look as surprised as newborn child. :) the first C compiler was not written in C, maybe the language was assembly or even "worse": machine language. – holex Aug 03 '12 at 15:49
  • @holex , I come across this "VUCK was a compiler designed to handle multiple languages, including C and Pascal in beginning days" then I started thinking how VUCK compiler was made? Is that they used some other compile to compile VUCK and if so where does it being? that's the reason I asked this question. – Viswesn Aug 03 '12 at 15:53
  • @Viswesn the mother of all languages is the _binary code_. it was invented by **John von Neumann**, he was a Hungarian guy. like I am. :) – holex Aug 03 '12 at 15:57

4 Answers4

5

There is no chicken and egg here. glibc is compiled with the compiler you are using.

That compiler was first compiled with a previous version of the same compiler. Then it can compile itself as well.

The real chicken-and-egg problem was solved in the 1950's when someone had to write the world's first compiler. After that, you can use one compiler to compile the next one.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
  • I suppose the first "compiler" what actually an interpreter then? –  Aug 03 '12 at 15:25
  • @AlexBelanger I really don't think it was an interpreter. An assembler maybe. –  Aug 03 '12 at 15:27
  • Yes, probably. You don't have to implement the whole language at once, so perhaps integer ops, if-else, and some looping. Then you can use that part of the language to implement the rest later. – Bo Persson Aug 03 '12 at 15:33
4

There are two basic ways to build a new compiler:

  1. If you're writing a new compiler for an established language like C, use an existing compiler from a different vendor to build your new compiler. For example, you could use the C compiler shipped with HP-UX to build gcc.

  2. If you're writing a compiler for a new language, start by implementing a very simple compiler in a different language (the first C compiler was written in PDP-11 assembler). This initial compiler will only recognize a small subset of the target language; basically enough to do some file I/O and some simple statements. Write a new compiler in the target language subset and build it with your first compiler. Now write a slightly more capable compiler that can recognize a larger subset of the target language, and build it with the second compiler. Repeat the process until you have a compiler capable of recognizing the full target language.

John Bode
  • 119,563
  • 19
  • 122
  • 198
1

They did not use some other compiler. You can write a C program that doesn't use glibc by simply telling the compiler not to use it. So something like this:

gcc main.c -nostdlib
1

This is an interesting question. I think you are wondering in what language is written a compiler of a new language, aren't you? Well, if we had only Assembly language (for instance,x86), the only way to write a C compiler would be in Assembly language. Later, we could write a better, yet more powerful compiler written in C by using our assembly-written compiler, and so on... An the question arises: how did the early programmers write the first assembly compiler? My father told me: by manually entering the 1's and 0's! :-)

Claudi
  • 5,224
  • 17
  • 30