197

Sometimes while programming in different languages (C/C++, C#), this thought comes to my mind:

  • Is each and every language written in the C programming language?
  • Is the C language the mother/father of all languages?
  • Is each concept (OOP, etc.) all implemented in C?

Am I in right direction?

53
  • 59
    @X.L.Ant: many (maybe even most) C compilers are written in C. Dec 22, 2014 at 11:07
  • 34
    @Neil: C++ doesn't compile to anything. C++ is a language. Languages don't compile, compilers do. Dec 22, 2014 at 11:07
  • 12
    @X.L.Ant: I don't think so. But the first Oberon compiler, for example, was written in Oberon and then hand-translated (which is a form of compilation, I guess) to Fortran. This compiler was then compiled with a Fortran compiler, the resulting Oberon compiler was used to compile the Oberon compiler and from that point on, the previous version of the compiler was used to compile the next one. Dec 22, 2014 at 11:10
  • 19
    @Neil It's not really that pedantic. It's accurate: a language is a spec. It may be implemented as a compiler, as an interpreter, a hybrid, etc. You can write a compiler for a language, but the compiler is not the language. I guess the issue gets confusing because there are languages for which there is no spec written anywhere except for its reference implementation. But even in those cases, I'd argue the language (i.e. the ideal the author had in his/her mind) is different from the implementation/compiler/interpreter/etc.
    – Andres F.
    Dec 22, 2014 at 12:54
  • 25
    Downvoters: this is a pretty reasonable question with a clear answer. That the answer is "no" is no reason to downvote. Instead, consider answering and explaining.
    – Andres F.
    Dec 22, 2014 at 12:57

10 Answers 10

218

No.

OCaml, Haskell, Lisp dialects like Scheme, and several other languages are often used in the development of hobby languages.

Many languages are implemented in C because it's a ubiquitous language, and compiler-writing tools like lexer-parser generators (such as yacc and bison) are well-understood and almost as ubiquitous.

But C itself couldn't originally be developed in C when it was first created. It was, in fact, originally developed using the B language. Earlier languages (like Fortran) were usually bootstrapped using a native assembly language or even machine code long before C ever existed.

Unrelatedly, language paradigms like OOP are generally language-agnostic. The functional paradigm, for example, was developed (by Alonzo Church) as a foundation of mathematics long before any programming language ever existed. The procedural and structured programming paradigms came out of the mathematical work of theorists like John von Neumann. Object-orientation was developed by several different and unrelated efforts, some out of the lambda calculus (the functional paradigm) and some out of dynamic programming systems like SmallTalk at Xerox PARC by Alan Kay.

C is merely a tiny part of the story, decades after these ideas came into being.

24
  • 42
    While it's true that the first C compilers obviously couldn't be written in C, it's certainly possible now.
    – reirab
    Dec 22, 2014 at 15:14
  • 19
    @reirab Posible AND true. GCC is written in C and usally compiled using GCC.
    – Darkhogg
    Dec 22, 2014 at 23:30
  • 9
    Of course, GCC is now being rewritten in C++, but that's not as important as the fact that the first C compiler couldn't be written in C.
    – greyfade
    Dec 23, 2014 at 1:35
  • 11
    @greyfade gcc hasn't been C for some time. It is not "now being rewritten" it is "has been written in C++ for over two years" (its even older than that though, thats when the merge happened that moved it to C++).
    – user40980
    Dec 23, 2014 at 4:26
  • 14
    @greyfade isn't "C but with C++ features" sort-of the definition of C++?
    – KutuluMike
    Dec 23, 2014 at 12:52
96

Is each and every language written in C language?

A language is a set of abstract mathematical rules and restrictions ("if I write this, that happens"). It isn't written in anything, really.

It is specified, usually in a mixture of a formalized subset of English, mathematical notation, and maybe some specialized specification language. The syntax is often specified in a variant of EBNF or ABNF.

For example, here is the specification of the for expression from the ISO Ruby Language Specification:

§11.5.2.3.4 The for expression

Syntax

  • for-expression for for-variable [no line-terminator here] in expression do-clause end
  • for-variable left-hand-side | multiple-left-hand-side

Semantics

A for-expression is evaluated as follows:

  1. Evaluate the expression. If the evaluation of the expression is terminated by a break-expression, next-expression, or redo-expression, the behavior is unspecified. Otherwise, let O be the resulting value.
  2. Let E be the primary-method-invocation of the form primary-expression [no line-terminator here].each do | block-parameter-list | block-body end, where the value of the primary-expression is O, the block-parameter-list is the for-variable, the block-body is the compound-statement of the do-clause.

    Evaluate E; however, if a block whose block-body is the compound-statement of the do-clause of the for-expression is called during this evaluation, the steps in §11.3.3 except the Step c) and the Step e) 4) shall be taken for the evaluation of this call.

  3. The value of the for-expression is the resulting value of the invocation.

Here's a different example from the type conformance rules of Scala:

The polymorphic type [a1 >: L1 <: U1 , … , an >: Ln <: Un]T conforms to the polymorphic type [a1 >: L′1 <: U′1 , … , an >: L′n <: U′n]T′ if, assuming L′1 <: a1 <: U′1 , … , L′n <: an <: U′n one has T <: T′ and Li <: L′i and U′i <: Ui for i ∈ { 1 , … , n }.


Is C language mother/father of all languages?

No, it is not. C is pretty young. There are a lot of old languages. Since time travel is physically impossible, it is simply impossible for C to have had any influence whatsoever on those old languages.

  • Plankalkül (1943)
  • Speedcoding (1953)
  • Fortran (1954)
  • IPL (1956)
  • Lisp (1958)
  • Algol (1958)
  • COBOL (1959)
  • JOVIAL (1960)
  • APL (1962)
  • SIMULA (1962)
  • SNOBOL (1962)
  • CPL (1963)
  • BASIC (1964)
  • PL/I (1964)
  • RPG (1964)
  • BCPL (1966)
  • ISWIM (1966)
  • MUMPS (1967)
  • Forth (1968)
  • LOGO (1968)
  • REFAL (1968)
  • B (1969)
  • BLISS (1970)
  • Pascal (1971)
  • KRL (1971)
  • Smalltalk (1972)

All of those existed before C was even invented. And many others have no influence of C in them, even after it existed. The PASCAL-family of languages (ALGOL-58, ALGOL-60, ALGOL-X, ALGOL-W, PASCAL, Modula-2, Oberon, Oberon-2, Active Oberon, Component Pascal) is a completely separate lineage. The whole Lisp family (LISP, Franz Lisp, InterLisp, MacLisp, Scheme, Flavors, LOOPS, CommonLoops, Dylan, CommonLisp, Arc, Clojure, Racket, etc.) is unrelated as well. Functional languages (ISWIM, KRL, Miranda, ML, SML, CAML, OCaml, F#, Haskell, Gofer, Clean) and the whole dependently-typed family (Agda, Coq, GURU, Idris) are about as far from C as possible. The same is true for the Smalltalk family (Smalltalk, Self, Newspeak, Us, Korz), the logic programming family (PLANNER, Prolog, Mercury), SQL, and many others.

Each concept (OOP etc) is all implemented in C language?

The first languages with OO concepts were Simula (1960) and Smalltalk (1972), but object-oriented systems had been built as far back as 1953 (without calling them that). Again, that's long before C existed, so OO cannot possibly have any relation to C.

9
50

Most of the core of many important languages is written in C, but things are changing:

  • the reference implementation of Python (CPython) is written in C (but there are other implementations written in other languages, e.g. Jython / Java, PyPy / Python, IronPython / C#...)
  • PHP Zend Engine is written in C
  • very first Java compiler developed by Sun Microsystems was written in C, but now the class libraries are always written in Java (since they are intended to be run using the Java VM itself). Certain libraries using JNI (Java Native Interface) may be partially written in a variety of other languages, as they are intended to be used OUTSIDE the JVM.

    The Sun/Oracle VM is written in C++. The BEA/Weblogic/Oracle VM is written in C. But there are JVM written in Java, Lisp, SmallTalk (IBM)...

  • Perl is implemented as a core interpreter, written in C, together with a large collection of modules, written in Perl and C (but Pugs, a compiler and interpreter for the Perl 6 programming language, is written in Haskell)
  • the official Ruby interpreter, often referred to as the Matz's Ruby Interpreter or MRI, is written in C and uses its own Ruby-specific virtual machine (but there is JRuby, a Java implementation that runs on the Java virtual machine; Rubinius, a C++ bytecode virtual machine that uses LLVM to compile to machine code at runtime...)
  • about 50% of R is written in C
  • and, of course, C is (was) written in C! (but the first C compiler, targeted to the PDP-11, was a mix of B and assembler).

There are many reasons why C was often chosen: performance, portability, experience.

The last probably being the most important: Python was started in 1991, PHP in 1994/1995, Perl in 1988, Ruby in 1995. In those years Java was just released and C++ not yet well standardized.


Somewhat related:

8
  • 5
    From the perspective of compilers/interpreters implementation, C has been/is a reference point. In addition it has directly or indirectly influenced many later languages (at least syntactically).
    – manlio
    Dec 22, 2014 at 10:41
  • 2
    pretty soon, you'll be able to say that C# was written in C#! (kind of)
    – DLeh
    Dec 22, 2014 at 18:44
  • 1
    Most of Mono (which includes a C# compiler and many/most of the .NET base class library) is written in C#. Dec 23, 2014 at 6:31
  • 3
    The answer to the question "is C the mother/father of all languages?" is "no", so I don't think it's helpful to provide lots of examples which are written in C. Counter-examples would help, but your choices are still descended from C. For example, even if Java, Python, etc. are now self-hosting, they were still bootstrapped from C, so they're like "grandchildren" of C. Languages like LISP, FORTRAN, ML and (of course) machine code are true counter-examples, since C was never involved in their creation.
    – Warbo
    Dec 23, 2014 at 18:39
  • 2
    The aspiration for many languages is, of course, to be implemented as far as possible in itself. However, it seems like most languages depend on C because most languages need to be able to call C to be useful; the majority of modern operating system APIs and useful libraries tend to have C bindings. You also have to be careful about what you mean by "written in". A language implementation typically has multiple parts: at least a compiler and a runtime system. Runtime systems are often written in C to better interface with the OS.
    – Pseudonym
    Dec 24, 2014 at 0:21
11

No, some languages pre-date C. And many are implemented independently of C, e.g. see http://en.wikipedia.org/wiki/Lisp_%28programming_language%29

11
  • 2
    There are many implementations of Java, most are written in Java. The GNU implementation of Objective-C is written in C (or C++, they changed recently, I believe), the LLVM implementation is written in C++, and there used to be an interpreter written in C#. There are many implementations of Python, one is written in RPython, one in Java, one in C#, and one in C. PHP has six main implementations, two in Java, two in C#, one in C and one in C++. Dec 22, 2014 at 9:28
  • 1
    No. Language designers are certainly influenced by other languages, but they can choose to ignore those influences if they so wish. Dec 22, 2014 at 11:08
  • 2
    @FaizanRabbani languages, in essence, are concepts and choices of paradigms, patterns and compromises - very often a "language is created/adapted from other language(s)" but that's completely unrelated to the implementation language of its compiler; language X can be derived from language Y but implemented in C or something completely else - and that often is the case. And in this case, the 'conceptual ancestor' is important but the compiler language is just a barely relevant technical nuance that can change over time.
    – Peteris
    Dec 22, 2014 at 16:44
  • 3
    That last link if of dubious value - too many mistakes in it to really take it seriously. Dec 22, 2014 at 16:50
  • 4
    @SebastianGodelet: HotSpot is not an implementation of the Java language. It's an implementation of the JVM bytecode language. Those are two completely different languages. The most widely used implementations of the Java language are javac from the Oracle JDK / OpenJDK written by Martin Odersky (of Scala fame) in 100% Java, the Eclipse Compiler, written in 100% Java (derived from IBM's Jikes compiler), the compiler from IBM's J9, also derived from Jikes and 100% Java. AFAIK, the only Java compiler in somewhat widespread use that is not written in Java is GCJ Dec 23, 2014 at 15:54
5

I would make this a comment if I could, but I can't so here goes:

One of the reasons C seems so ubiquitous is because it is one of the earliest languages developed, and an enormous amount of modern languages are based off of its structure (Java, Go, PHP, Perl, etc.) - making it seem like it's more places than it is.

Another oft-forgotten reason is that in 1973 Unix was rewritten in C and many of Unix's system calls are also available as C programs/functions, making the two highly interlinked. Since Unix was a powerful part of the development of modern programming as a whole, C was dragged along into infamy with it.

Having said all that, the answer to your question is "No". C is based off of a language called ALGOL, and there were many competitors both with ALGOL (FORTRAN, Lisp, COBOL) and C (none come to mind). Object-oriented programming, arguably the biggest paradigm-shift in programming design, did not originate with C - despite C++ being a very popular OOP language (it showed up first in Lisp or Simula 67, depending on who you ask). By the time OOP came about, C was such a popular language that it didn't need to be first - it was so popular that the C++ "expansion", so to speak, became one of the primary OOP languages too. It remains in modern use mainly because of its powerful memory control features (you can directly allocate and deallocate the memory your structures create), allowing it to create programs on tight memory budgets (think video games) and its highly optimized compiler (obviously depending on the compiler). Admittedly, even these features are losing ground as Java JIT compilation and in-language memory managers become more advanced.

3
3

Obviously not. How could the first C compiler be written in C if C wasn't exist before? This isn't the chicken and the egg problem.

There are many ways to write the first compiler of a language which are called bootstrapping

Moreover most compilers try to achieve self-hosting, or compile itself it its language, mainly to promote the language and the compiler itself

6
  • 13
    The first Oberon compiler was written in Oberon. That's perfectly fine, provided you are a professor and have lots of students that will hand-translate the compiler for you (which Prof. Wirth had). Dec 22, 2014 at 21:38
  • @Jorg that was mentioned in the bootstrapping article linked above so I don't bother writing that because this question is about C and no C compiler was written that way
    – phuclv
    Dec 23, 2014 at 2:39
  • 15
    @JörgWMittag - the first automated Oberon compiler was written in Oberon. The actual first Oberon compiler was a bunch of students.
    – nnnnnn
    Dec 23, 2014 at 22:33
  • 4
    @nnnnnn: I would consider this "bunch of students" an interpreter, not a compiler. Dec 25, 2014 at 18:23
  • 5
    @Paŭlo Ebermann To add another human element: "computer" was originally a job title. Jan 3, 2015 at 6:59
3

Programming languages are specifications (not software!) usually written in some English document (with some formalization, e.g. EBNF for most of the syntax; sometimes their semantics is also partly formalized).

For example, C11 is defined by n1570 (which you should read). Some dialect of Scheme is defined by R5RS (which you should also read, it is very well written).

Programming languages may be implemented by some software. Sometimes that software is a compiler written in the programming language itself. Read about bootstrapping compilers.

One can write a compiler in the compiled programming language itself. If that language XX is brand new, you need to go thru a temporary step which involves writing a minimal interpreter or compiler of a subset of that language in some other implementation language (perhaps C), and later your can throw away that temporary compiler or interpreter (which don't need to be "good", just to be enough to compile the other compiler). Once you compiled your XX compiler written in XX you can throw away your temporary compiler.

Often (but not always) the runtime system is partly written in C (in particular the garbage collector).

Notice that bones is a Scheme compiler and runtime entirely written in itself (and you can find many other examples of fully bootstrapped implementations).

BTW it is convenient to use C as the target language of compilers.

Today, a lot of programming languages implementations is free software or open source. Feel free to study (and perhaps contribute to) their source code!

The Programmation Automatique des Formules (literally "automatic formulae programming") programming language was designed and implemented in France (around 1959) by my father, Dimitri Starynkevitch (1919-1993). It is a BASIC like language (whose specification is written in French, on paper). See this web page for more.

Consider reading Queinnec's book Lisp in Small Pieces and Pitrat's book Artificial Beings, the conscience of a conscience machine about bootstrapped programming languages. The RefPerSys open source project aims to become one (but a lot of work remains to generate most of the code of this homoiconic software).

PS. Feel free to send me an email to basile@starynkevitch.net for details you don't want to share on a public forum, but mention the URL of your question in that email.

2
  • Golang was like that for a while; written in C until it was written in Go. Aug 20, 2020 at 19:11
  • this also answers the age old question, "which came first, egg or chicken??" chicken came first, as the first chicken came from some other creature and then laid chicken egg, if something else had laid the egg, it wouldn't be the chicken egg!! Mar 12, 2021 at 8:27
2

Here is a list of some programming languages that are not written in C, alongside the languages they are implemented in:

  • Haskell - Haskell
  • Idris - Haskell
  • Adga - Haskell
  • Clash - Haskell
  • PureScript - Haskell
  • Elm - Haskell
  • Mercury - Mercury
  • Rust - Rust (initially OCaml)
  • Go - Go
  • Crystal - Crystal
  • OCaml - OCaml
  • Frege - Frege + Java
  • Haxe - OCaml + Haxe
  • Scala - Scala
  • Futhark - Haskell
  • ATS - ATS

The best languages for implementing a compiler are probably going to be pretty far away from C. Functional languages give you things like recursion schemes and monadic parser combinators (provided you have typeclasses), which makes them especially suited for compiler work.

Second, to address your question as to whether C is the "mother/father of all programming languages" - not really. C was a well-designed language at the time it appeared, and it no doubt has influenced language designers who then went on to do very different things. But at the end of the day, Haskell departs from C in essentially every way possible. C is 45 years old and it is not surprising that we have learned to do better in the meantime.

Finally, to answer your third question, it is simply not the case that C implements "all the concepts". In particular, trying to implement some of the advanced concepts from functional programming (such as metamorphisms, or, god forbid, synchromorphisms) in C would be monstrously difficult. I am not particularly familiar with object-oriented programming, but I do know for a fact that some object-oriented languages have sum types.

4
  • C was never "an incredibly well-designed language." The warts that we see on it today were known to be warts from the very beginning. But, it was good enough to be the native language of the developer-friendly Unix operating system, and after Bell Labs pushed Unix out into the universities, C/Unix became a favorite language/OS for a generation of computer professionals. Sep 22, 2017 at 21:06
  • 2
    PS., There weren't a lot of original ideas in C. If You're looking for the mother/father of all block-structured, procedural programming languages you might want to have a look at ALGOL. Sep 22, 2017 at 21:09
  • Lisp Macros were much much better than C, and ALGOL and Smalltalk had blocks, closures, and nested functions to help organize code. Indeed Lisp could have been used as a Macro-processor for assembler and created code that was shorter and faster(custom processing of S-expressions) than early C. Simula which came out before C had polymorphism. Lisp, APL, and Smalltalk had "shells" which were fully functional (same code between shell and programs) unlike Unix's "sh" vs "C" allowing interpreted and compiled code to be interleaved. Pointers were easier in Lisp (rplaca/rplacd).
    – aoeu256
    Aug 9, 2019 at 12:53
  • 1
    The biggest advantage of C was it was easier to build "compilers" for C, and so it could spread more easily ... like a virus, and thanks to C modern programmers don't have a clue on how to build programs are modular (mutability hurts modularity), have no notion of adverbs/combinators/higher-order functions [manually write your loops every time], and our CPUs are limited by the "von neumann" bottleneck because our OS are written in C so we need our CPU to run C code for backwards compatibility.
    – aoeu256
    Aug 9, 2019 at 13:00
1

In addition to the answers given so far, I would like to add one of my favourite anecdotes related to programming languages.

There was a Basic Interpreter available on the Atari ST, which was called Omicron Basic.

Later, a compiler for that language was developed: written in Omicron Basic! The compiler compiled itself while being run by the interpreter.

Unfortunately, I don’t know, what the interpreter was originally programmed in. Probably in C, but since interpreters are much easier to implement than compilers it’s not too unlikely it was written in assembler.

3
  • Excellent. Indeed in my youth I worked for a French company that made a portable multitasking multiuser OS that was available on almost any CPU between 8 and 32 bits. Each port to a new CPU took around a month! The OS was written to 90% in a language called “M”. on the top of that they had their own cobol like application language written in M using à API defined in M. And of course their app software used portability guidelines in a very disciplined way. Porting to a new processor just required to adapt the 10% non-portable part (scheduling, memory management, ..).
    – Christophe
    Aug 17, 2021 at 19:33
  • Much more known on this “pull your self out of the swamp by your own hair” topic was the small C compiler that was able to compile itself. The principle is the same, but since it was C it is does not qualify for this question ;-)
    – Christophe
    Aug 17, 2021 at 19:44
  • PyPy works similarly. The toolchain for the RPython subset it's written in bootstraps from CPython.
    – ssokolow
    Sep 30, 2021 at 21:42
0

It is very common to write languages in C or C++ for several reasons, but not ubiquitous:

  1. The C ABI (not the language itself, but a given platform's implementation of the ABI) is basically the lingua franca for calling into dynamic libraries, so anything serious is going to need to support at least that.
  2. On pretty much anything except Linux, the kernel system call interface is API-unstable and making system calls requires calling into a dynamic library which is developed and distributed with the kernel, serves as the stable API, and exposes a C ABI. (libSystem on MacOS, which also contains libc. NTDLL on Windows. etc.)
  3. For a long time, nothing but C and C++ offered a combination of features compelling enough (and it took a while for C++ compilers to get to that point).
  4. Haskell, which is now becoming a popular choice for writing languages, is very different from what a lot of programmers are used to and is decades younger than C.

In fact, there's a perception among some systems programmers that a language isn't serious until it's got a mature self-hosting compiler. (ie. At least one of the mature compilers for the language is written in that same language... thus proving the language's suitability for such tasks and removing its dependence on competitors.)

The Wikipedia "Self-hosting (compilers)" page I linked has a list of languages with self-hosting compilers.

Also, I should note that other factors do come into play.

For example, the official Rust compiler was never written in C or C++ (it started in Ocaml, then was rewritten in Rust to become self-hosting), but it's implemented as a frontend to LLVM for reasons completely unrelated to LLVM being written in C++.

(Namely, that the Rust developers saw how long it took for the LLVM developers to get their optimization passes up into the same ballpart of effectiveness as GCC's and didn't want to needlessly duplicate that effort.)

Not the answer you're looking for? Browse other questions tagged or ask your own question.