Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is gcc C compiler written in C itself?

Is gcc C compiler written in C itself ? Or is it written in Assembly ? If the compiler is written in C, then what is the compiler used to compile the compiler code ?

like image 462
euphoria83 Avatar asked Apr 14 '11 01:04

euphoria83


People also ask

Does C have its own compiler?

Yes, C programs are first compiled to generate the object code and then that object code is Run.

Is GNU written in C?

The GNU operating system itself was started using C and Lisp programming languages, so many of its components are written in C.

How does GCC work in C?

GCC is an integrated collection of compilers for several major programming languages, which as of this writing are C, C++, Objective-C, Java, FORTRAN, and Ada. The GNU compilers all generate machine code, not higher-level language code which is then translated via another compiler.


1 Answers

The specific history to gcc is given at the GCC Wiki. The more general point is that compilers are generally originally compiled with some other compiler until they are powerful enough to compile themselves. Alternately, it is possible to write a basic compiler that can handle a subset of your features in assembler, and build up from there. But again, this is almost never needed anymore. There are plenty of compilers available, in a variety of languages. Even when Stephen Johnson was writing pcc (one of the first C compilers), there were compilers for B available, along with many other languages. gcc had several compilers to pick from to build it originally, and RMS says he was using the Pastel compiler at least during his initial development.

Remember, there is no requirement that a C compiler be written in C. You could write it in Perl if you wanted to. There is no requirement that a compiler for a given platform be originally written on that platform (embedded systems almost always are compiled on some other system). So there are many ways to get yourself bootstrapped.

This question has some interesting subtleties related to the first instance of bootstrapping the compiler. If you were very clever, you could make use of that bootstrap to do something incredible, brilliant and terrifying.

like image 152
Rob Napier Avatar answered Oct 02 '22 20:10

Rob Napier