199

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?

FaizanHussainRabbani
  • 2,255
  • 2
  • 15
  • 22
  • 2
    C++ used to compile to C, but now it can compile directly to assembly, and many languages, Java included, are implemented using C++, not C. – Neil Dec 22 '14 at 08:37
  • 59
    @X.L.Ant: many (maybe even most) C compilers are written in C. – Jörg W Mittag Dec 22 '14 at 11:07
  • 34
    @Neil: C++ doesn't compile to anything. C++ is a language. Languages don't compile, compilers do. – Jörg W Mittag Dec 22 '14 at 11:07
  • 1
    @JörgWMittag I know, it was a joke. First C compiler wasn't, I guess :) – xlecoustillier Dec 22 '14 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. – Jörg W Mittag Dec 22 '14 at 11:10
  • 6
    Ironically, the OP tagged this question with [tag:clang] which is a C compiler, C++ compiler and Objective-C compiler written in C++. – Jörg W Mittag Dec 22 '14 at 11:11
  • 3
    @JörgWMittag Bit of a pedantic point, isn't it? Pretty sure binary representation of characters don't just pick themselves up and turn themselves into another series of characters. If there was confusion on your part, then I assure you that no, language *don't* compile themselves. Hope that clarifies it for you. – Neil Dec 22 '14 at 11:31
  • 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 '14 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 '14 at 12:57
  • @AndresF. Was there any confusion in your mind? I thought that it is fairly obvious that I was talking about compilers. If anyone misunderstood that, I apologize. I assumed (perhaps wrongly) that most people wouldn't have made a non-sensical interpretation out of that. However if I can be frank, I still don't think most people interpreted that way. – Neil Dec 22 '14 at 13:07
  • 5
    @Neil I get that you meant "compiler". But the distinction is important because the person asking the question is evidently a novice, likely to be confused by this. – Andres F. Dec 22 '14 at 13:13
  • @AndresF. Then my sincerest apologies. OP please disregard what I wrote. – Neil Dec 22 '14 at 13:23
  • 2
    Most of the [MLton](https://github.com/mlton/mlton) Standard ML compiler is written in Standard ML and compiled the previous verison of MLton itself. Only the runtime is written in C since it requires control over where and how things are laid out in memory, which safe languages generally don't provide. – Doval Dec 22 '14 at 14:14
  • 1
    @Neil I think distinction is important also bacause some languages have more than implementation. For Pascal there is Turbo Pascal compiler written in assembly, GNU Pascal written in C and FreePascal writeen in Pascal, amongst others. Python has implementations in C (CPython), Java (Jython), Python (PyPy) and C# (IronPython), amongst others. – el.pescado - нет войне Dec 22 '14 at 14:53
  • @Neil We can also work on different languages at the same time? For example, once I was working on C# project, but I needed some libraries that I designed purely on C & C++. Does the same thing happens when creating languages too? – FaizanHussainRabbani Dec 22 '14 at 15:00
  • 1
    @FaizanRabbani Definitely. For example, Python has libraries which are compiled in C++. The reasons behind this are almost always for creating very efficient libraries, however they also tend to have platform-specific issues. Java virtual machine is implemented with the platform in mind in which it is being installed, and in fact there are many, despite there being only one Java language. – Neil Dec 22 '14 at 16:37
  • @Neil Thank you so much for helping me out on this one. :) – FaizanHussainRabbani Dec 22 '14 at 16:39
  • @FaizanRabbani No problem. My advice is to keep dependencies for other technologies to an absolute minimum. It will make your language that much more instable than it would be otherwise (though granted sometimes it is a necessary evil). – Neil Dec 22 '14 at 16:42
  • @Neil I am interested in Android development but I don't want to use Java. It may sound weird and stupid. I know Google provides NDK so that Android apps can be developed on C/C++ platform, but they discourage to do so. So I am doing a research work on Android apps these days. :) thank you any way. – FaizanHussainRabbani Dec 22 '14 at 16:45
  • 2
    @FaizanRabbani Happy to help. You should consider learning Java in order to write Android apps. Java is a very popular language and it is nice to have on the toolbelt. – Neil Dec 22 '14 at 16:50
  • @Neil So I should not consider developing apps on Android without java. Thank you :) – FaizanHussainRabbani Dec 22 '14 at 16:56
  • @JörgWMittag Congratulations, you are the first person since my introductory programming course more than five years ago to ever mention Oberon. Higher education is finally paying off! – Lilienthal Dec 22 '14 at 20:37
  • 4
    No computer language is written in C. Many compilers and/or interpreters for many different computer languages are written in C; however, most computer languages are described using some sort of meta-syntax, such as Backus-Naur Form (aka Backus Normal Form). – Bob Jarvis - Слава Україні Dec 23 '14 at 03:36
  • 2
    There were many languages which were invented (and had compilers) before C. COBOL and Fortran are two languages that (barely) still exist that predate C. I'm sure there are others. – Daniel R Hicks Dec 23 '14 at 17:52
  • 5
    @DanielRHicks: Correct. Fortran (1954), Lisp (1958), COBOL (1959), APL (1962), BASIC (1964), PL/I (1964), RPG (1964), Forth (1968), LOGO (1968), Pascal (1971), and Smalltalk (1972) are some of the languages that predate C and are still in active use today. – Jörg W Mittag Dec 23 '14 at 19:02
  • @JörgWMittag - Well, I'd question whether some are in "active use" today (and whether RPG was ever a "language" in the first place), but the point is clearly made that many languages already existed before C was "born". – Daniel R Hicks Dec 23 '14 at 19:07
  • @DanielRHicks: Me and my family benefit a great deal from the fact that, well past retirement age, my dad still makes quite a good living not just maintaining RPG code, but writing new greenfield systems in it as well, so I am a little biased, probably ;-) – Jörg W Mittag Dec 23 '14 at 19:21
  • @JörgWMittag - Many years back I was managing the (very early) computer facilities for our church. We had a basic data management package, but, in order to print mailing labels, etc, I wrote a report printing program in Pascal. Only after I had it working did I realize that I had basically reinvented RPG (one of the few languages to ever implement "come from"). – Daniel R Hicks Dec 23 '14 at 22:29
  • Another dimension on which language implementations' languages vary is the runtime library. For example the code that calls main(), or the code that implements printf() *COULD* be assembly. The code that implements a "standard prelude" for a language like Haskell could be a mixture of languages. I wrote a Scheme interpreter in C++ in which to write a Scheme compiler which emitted machine code directly and interfaced with an assembly language runtime library. – cardiff space man Dec 24 '14 at 01:29
  • @DanielRHicks I suspect that you haven't used, or perhaps don't understand, any of the modern forms of RPG (which never implemented a "come from" feature). And it seems likely you didn't grasp earlier RPG incarnations back when alternative languages were far less useful for relevant business development. – user2338816 Dec 24 '14 at 07:19
  • @user2338816 - It's been about 6 years since I last worked with RPG 4, and I was never really an expert at it, but yes, it did implement "come from" -- you just has to recognize that fact. And I do appreciate at least the basic features of the language for business processing (especially the "come from"). If I hadn't, I wouldn't have reinvented it. – Daniel R Hicks Dec 24 '14 at 07:25
  • @DanielRHicks If there is a "come from", please provide a link/reference. (Also, note that even RPG IV is now almost 14 years old and practically obsoleted.) – user2338816 Dec 24 '14 at 11:53
  • 1
    See my similar question [here](http://programmers.stackexchange.com/questions/129123/were-the-first-assemblers-written-in-machine-code). I highly suggest reading the book I mention in the beginning of that question, as it would get you way beyond the confusion in your question. – The111 Dec 25 '14 at 01:32
  • 1
    @Jörg. Neil is absolutely correct here. The first C++ compilers were producing C-Code, which was then compiled. Took a while before we had compilers that produced native code. – Zane Dec 25 '14 at 12:44
  • 1
    @Zane: C++ is a language. A language is an abstract set of mathematical rules and restrictions. It doesn't compile to anything. Languages don't compile. Compilers compile. Cfront (the first C++ compiler) compiles C++ to C. C++ doesn't compile to anything, because it isn't a compiler, it's a language. – Jörg W Mittag Dec 25 '14 at 13:53
  • 1
    The Rust compiler was originally written in OCaml and now is in pure Rust. This is the case with many languages. – Manishearth Dec 25 '14 at 15:38
  • @Jörg. C++ [programs] used to compile to C. Natural language can be a problem if you think too formally. http://en.wikipedia.org/wiki/Ellipsis_(linguistics) 8^) – Zane Dec 26 '14 at 15:39
  • 1
    @Zane: C++ programs don't compile either (unless they are compilers). This *entire* question is based upon the fact that the OP doesn't understand the fundamental distinction between a programming language and a compiler. It's really not a difficult concept: compilers compile. Not-compilers don't compile. C++ is not a compiler, it is a language, ergo, it doesn't compile. There exist C++ compilers which compile to C (Comeau, for example), but that doesn't mean that C++ compiles to C. There are also interpreters for C++, by that some logic would you say that C++ is an interpreted language? – Jörg W Mittag Dec 27 '14 at 01:05
  • 1
    See also: "[A language that doesn't use 'C'?](http://stackoverflow.com/q/1741368/90527)". – outis Dec 27 '14 at 20:51
  • 1
    @AndresF. No, it is not a pretty reasonable question with a clear answer. It is four separate questions. The meaning of the first question is entirely unclear - what does it mean to "write" one language in another? The second question's OK. The third question is far too broad - what does "each concept" actually include? And the fourth question is entirely meaningless. Please don't tell other people that their downvotes are unjustified. I would VTC if I could. – Dawood ibn Kareem Dec 28 '14 at 11:37
  • 1
    @Jörg: C++ is not a language - it's a string of three characters. – Zane Dec 28 '14 at 14:17
  • 1
    @DavidWallace Uh, it's self-evident what it means to write a language X in another language Y: it means writing X's compiler/interpreter/whatnot using Y. The answer in this case is "no, not every compiler/interpreter is written in C", but that's no reason to downvote. So you're allowed to VTC, and I'm allowed to vote against it. I'm also free to tell people whatever I want to tell them; my opinion is not binding after all. Please don't tell me what I can or cannot do. – Andres F. Dec 28 '14 at 16:48
  • 1
    @DavidWallace The question is also interesting because it both has a clear answer (see accepted answer, which is great), and is also a question likely to be asked by many newbies. – Andres F. Dec 28 '14 at 16:52
  • Right, so does it mean "every compiler/interpreter for X is written in Y", does it mean "there is a compiler/interpreter for X that's written in Y", or does it mean "the first compiler/interpreter for X was written in Y"? You say "self-evident", @AndresF. and that's your opinion. My opinion is different, but that's not the point. The point is, you have no right at all to come here and tell people they shouldn't downvote. It's perfectly valid to downvote this question, just as it's perfectly valid to upvote this. But how dare you come here and tell me what my opinion should be! – Dawood ibn Kareem Dec 28 '14 at 16:53
  • @DavidWallace "Every" means "every", what's ambiguous about that? – Andres F. Dec 28 '14 at 16:55
  • It says "every language". It doesn't say "every compiler for every language". – Dawood ibn Kareem Dec 28 '14 at 16:55
  • 2
    @DavidWallace We've been through this already. "Every language" is newbie-speak for "every implementation of a language". "Languages" are specs, which may be implemented as a compiler/interpreter/etc (though it's typical of novices to conflate the two; almost everyone of us made this mistake at least once). With this in mind, it's clear the OP is asking whether *every* implementation is written in C. Feel free to edit the question if you feel it would make it clearer, you have enough rep. Other than that, suit yourself: downvote, don't downvote, whatever. – Andres F. Dec 28 '14 at 16:59
  • Not at all. "Is there an implementation of Python that's written in C" is an entirely different question from "is every implementation of Python written in C". Interestingly, most of the people who have answered this question have answered something like "was the first implementation of Python written in C". It's fine to choose one interpretation of an unclear question; although in my experience, people who do so often pick an interpretation that's different from what the OP intended. But to turn round and argue that the question isn't unclear, and that people shouldn't downvote it, ... – Dawood ibn Kareem Dec 28 '14 at 17:05
  • ... because YOU know what the OP meant, is heavy handed and arrogant. You instructed people not to downvote. You shouldn't be doing that. @AndresF. Other people's opinions are valid too. – Dawood ibn Kareem Dec 28 '14 at 17:05
  • 1
    @DavidWallace you truly have some issues against this question so kindly try not to waste your precious time for it anymore. – FaizanHussainRabbani Dec 28 '14 at 17:45
  • 2
    @DavidWallace - if you think that there is an issue with the question, do edit it to make it more concise and correct. – Angel Koh Dec 29 '14 at 08:23
  • 2
    @DanielRHicks, COBOL "barely" still exists? According to this, 90% of financial transactions are done in COBOL, and 5 billion lines of new COBOL code are added to live systems every year ... https://cis.hfcc.edu/faq/cobol – JoelFan Dec 31 '14 at 13:28
  • https://en.wikipedia.org/wiki/Timeline_of_programming_languages has a list of languages - many are from decades before C was written. And https://en.wikipedia.org/wiki/Generational_list_of_programming_languages is a family tree sort of version. This is also a good read: https://en.wikipedia.org/wiki/History_of_programming_languages – Jerry Jeremiah Sep 18 '17 at 22:51

10 Answers10

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.

greyfade
  • 11,103
  • 2
  • 40
  • 43
  • 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 '14 at 15:14
  • 19
    @reirab Posible *AND* true. GCC is written in C and usally compiled *using GCC*. – Darkhogg Dec 22 '14 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 '14 at 01:35
  • 11
    @greyfade [gcc](https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=2b15d2ba7eb3a25dfb15a7300f4ee7a141ee8539) 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++). –  Dec 23 '14 at 04:26
  • @MichaelT: To be fair, most of it is still basically C, but depending on C++ features. That's what I mean. – greyfade Dec 23 '14 at 08:24
  • 14
    @greyfade isn't "C but with C++ features" sort-of the definition of C++? – KutuluMike Dec 23 '14 at 12:52
  • @Michael well, sort of. C++ hasn't been a true superset of C for a while now though. greyfade it _could_ have been written in C. There just wouldn't have been a programmatic compiler for it, so it would've have to have been translated by hand, which is a huge pain. – Cubic Dec 23 '14 at 17:00
  • 2
    @reirab -- IIRC, Wirth's Algol W compiler was originally written in Algol W, then hand-translated into assembler to "bootstrap" it. – Daniel R Hicks Dec 23 '14 at 17:56
  • 2
    The original C++ compiler (called `cfront`) really compiled to C. That is, when you compiled a C++ program, you got a C program, which you then compiled using a C compiler. So you could definitely say that C++ was originally written in C. – Gabe Dec 23 '14 at 19:09
  • 2
    When I was at university the idea of obtaining C for use on the mainframe was being discussed (it arrived while I was there). There were lots of languages to program in before it was ported across. I've always thought of C as a kind of "new" language as a result. – Francis Davey Dec 24 '14 at 07:28
  • What are OCaml, Haskell, and Scheme written in? – joshreesjones Dec 25 '14 at 21:04
  • 2
    @mathguy54: There are more than one implementation of each, but: OCaml is bootstrapped with C and written in its own ML dialect. Glasgow Haskell is written in Haskell and compiles to C. There are hundreds of Scheme compilers, some written in C, some in Scheme, some in ML, several in JavaScript, and many others. The goal of most languages is to be self-hosting, so that they can compile their own source code. C is a common starting point, but it is by no means the only one. – greyfade Dec 26 '14 at 00:21
  • Strangely, on Linux, I know no language implementation which does not depend or use any C code (in user land). One could "easily" implement a bootstrapped language compiler which emits e.g. an ELF executable (with direct syscalls), but I cannot name any such free software on Linux. Do you know some? (all implementations of Ocaml, Scheme, Haskell I heard of have some part -usually their runtime & GC- coded in C; Scheme 48 is bootstrapped, but generates C code). – Basile Starynkevitch Dec 28 '14 at 14:15
  • 2
    @Michael: _"isn't 'C but with C++ features' sort-of the definition of C++"_ NO! – Lightness Races in Orbit Dec 28 '14 at 16:46
  • @BasileStarynkevitch: This is why C is called the *lingua Franca* of programming. It's so ubiquitous that it's the standard for all FFI, so it's nearly impossible to find a language that *doesn't* have a C interface of some kind. If there is a modern language that doesn't use C somewhere, I don't know of it, but ML dialects and languages like Fortran and Pascal have historically minimized the presence of C, either by predating it or because they're effective systems languages already. – greyfade Dec 28 '14 at 20:03
  • I still find that quite strange.... – Basile Starynkevitch Dec 28 '14 at 20:06
  • @BasileStarynkevitch: Why? – greyfade Dec 28 '14 at 21:42
  • Because there are a lot of things that cannot be done in portable C (continuations, closures, stack introspection, tail-recursion, ...) and could benefit from another low level language. See e.g. GNU epsilon – Basile Starynkevitch Dec 28 '14 at 21:43
  • 2
    @BasileStarynkevitch: If something can not be done in portable C, then it can not be done in non-portable assembly language. By your assertion, Haskell can't exist. No, continuations, closures, etc., can all be simulated straight-forwardly using well-known and common techniques. Realize that all of those things you named can be done just by clever manipulation of stack allocations (with the exception of closures, which can be done trivially on the heap; remember that C++ recently got closures and is getting continuations in a future standard, both of which already exist in libraries.) – greyfade Dec 29 '14 at 01:27
  • From what I have been told by CS teachers, it is possible to write a language with itself. I guess you probably need a little assembly/other to bootstrap yourself, but the idea is that you can bootstrap yourself if planed correctly. – Jonathon Mar 11 '15 at 19:40
  • @JonathonWisnoski: Yes, and I tried to make that clear: Until you have a working compiler, it's not possible to write a compiler for a language in that language. It's the chicken-and-egg problem. Others have pointed out that you can "compile" a language by hand, but that's still writing a compiler in another language, just with the extra step of translation. But the goal of most languages is to ultimately self-compile the compiler in the language, as nearly all C compilers do today. – greyfade Mar 11 '15 at 20:57
  • That `cc` was compiled with `cc` was vital to [Ken's Famous Hack](https://softwareengineering.stackexchange.com/questions/184874/is-ken-thompsons-compiler-hack-still-a-threat) – Rob K Sep 22 '17 at 20:49
  • 1
    It is false that "The functional paradigm, for example, was developed mathematically (by Alonzo Church) as a branch of set theory long before any programming language ever existed". You are probably referring to $\lambda$-calculus, which was indeed invented by Alonzo Church, but it has nothing to do with set theory. It was one of the earliest descriptions of what it means to "compute", as a formalism on its own, quite unrelated to set theory. It was very influential in the development of computability theory and later of programming languages. – Andrej Bauer Jun 27 '19 at 13:08
  • To expand a bit on where @AndrejBauer is coming from, there was a follow-up question (by me) about this question [here](https://cs.stackexchange.com/questions/111217/lambda-calculus-as-a-branch-of-set-theory/111236#111236) – Ben I. Jun 28 '19 at 00:48
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.

TehShrike
  • 745
  • 7
  • 14
Jörg W Mittag
  • 101,921
  • 24
  • 218
  • 318
  • 67
    [1970: Niklaus Wirth creates Pascal, a procedural language. Critics immediately denounce Pascal because it uses `x := x + y` syntax instead of the more familiar C-like `x = x + y`. This criticism happens in spite of the fact that C has not yet been invented...](http://james-iry.blogspot.de/2009/05/brief-incomplete-and-mostly-wrong.html) – leftaroundabout Dec 22 '14 at 23:35
  • 2
    @leftaroundabout: That's a great blogpost, one of my favorites for years. – Jörg W Mittag Dec 22 '14 at 23:38
  • You have BCPL twice. Even Martin Richards wasn't a time traveller. – Francis Davey Dec 23 '14 at 22:57
  • 1
    @FrancisDavey: Thanks. I started out compiling the list from memory, then I added dates I didn't remember by looking them up on Wikipedia. After that, I found a timeline of languages on Wikipedia, and picked a few more languages from there. Since the article on BCPL cites 1966, but the timeline cites 1967, I didn't notice that I had already added BCPL. I'll remove the duplicate. – Jörg W Mittag Dec 23 '14 at 23:03
  • You can add `dc` to your list. Fairly esoteric, but of interest because it is still included in just about every *nix out there. http://cm.bell-labs.com/cm/cs/who/dmr/hist.html – Digital Trauma Dec 24 '14 at 18:45
  • 1
    In your list, is not "htroF" spelled backwards? – chux - Reinstate Monica Jan 03 '15 at 06:53
  • 2
    “time travel is physically impossible” — That’s a highly contentious claim. Doesn’t detract from the value of this answer of course. – Konrad Rudolph Mar 14 '15 at 16:37
  • One _can_ implement OOP in C -- that is how CFront implemented C++ initially -- by translating C++ to C. – Michaelangel007 Jun 21 '16 at 16:25
  • I've written object oriented code in C, including polymorphism and inheritance, as a proof of concept. I proved both that it was possible and a mistake to try. – user10489 Sep 30 '21 at 23:10
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:

manlio
  • 4,166
  • 3
  • 23
  • 35
  • If I am not wrong, foundation of most modern languages were laid on C language? – FaizanHussainRabbani Dec 22 '14 at 09:27
  • 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 '14 at 10:41
  • 2
    pretty soon, you'll be able to say that C# was written in C#! (kind of) – DLeh Dec 22 '14 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#. – Katie Kilian Dec 23 '14 at 06:31
  • @FaizanRabbani - The foundations of modern languages were laid long before C became available. – Daniel R Hicks Dec 23 '14 at 17:57
  • @DanielRHicks Indeed. http://www.fourmilab.ch/babbage/sketch.html Do a text search for "cycle of operations" in this text from 1842 if you want to feel a bit like we're chasing our tails. – zxq9 Dec 23 '14 at 18:02
  • 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 '14 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 '14 at 00: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

Ofir
  • 313
  • 1
  • 4
  • Is Java written in C? What about Objective C, Python and PHP? – FaizanHussainRabbani Dec 22 '14 at 08:15
  • 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++. – Jörg W Mittag Dec 22 '14 at 09:28
  • Will it be okay to say that every language is created/adapted from other language(s)? @JörgWMittag – FaizanHussainRabbani Dec 22 '14 at 10:45
  • 1
    No. Language designers are certainly influenced by other languages, but they can choose to ignore those influences if they so wish. – Jörg W Mittag Dec 22 '14 at 11:08
  • By the way: you tagged this question with [tag:clang] which is (among others) an Objective-C compiler written in C++ and then ask whether Objective-C is written in C? I'm confused. – Jörg W Mittag Dec 22 '14 at 11:12
  • No I tagged it by mistake. This question was whether every modern language had its core designed on C language or not. – FaizanHussainRabbani Dec 22 '14 at 11:22
  • 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 '14 at 16:44
  • 3
    That last link if of dubious value - too many mistakes in it to really take it seriously. – Unknown Coder Dec 22 '14 at 16:50
  • I think the picture http://blog.terrencemiao.com/archives/the-family-tree-of-all-the-programming-languages-you-even-only-know-the-name is worthless. The author did not even try to define when there should be an arrow from one programming language to another. – miracle173 Dec 23 '14 at 09:05
  • @JörgWMittag, the Java JVM Hotspot engine is written in C++ – Sebastian Godelet Dec 23 '14 at 15:36
  • 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](http://jikes.sourceforge.net/) 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 – Jörg W Mittag Dec 23 '14 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.

WannabeCoder
  • 2,794
  • 5
  • 16
  • 19
  • 1
    this doesn't seem to offer anything substantial over points made and explained in prior answers, particularly in [top one](http://programmers.stackexchange.com/a/267089/31260), except for a questionable statement that "C is based off of a language called ALGOL" – gnat Dec 22 '14 at 14:22
  • 4
    C's basis in ALGOL is hardly questionable... See http://cm.bell-labs.com/who/dmr/chist.html, http://en.wikipedia.org/wiki/C_%28programming_language%29) – WannabeCoder Dec 22 '14 at 14:41
  • the [actual story](http://programmers.stackexchange.com/a/188463/31260 "explained in details eg here") is much more complicated and interesting than that; I would say the way things are laid out here is hardly helpful for readers – gnat Dec 22 '14 at 17:56
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

phuclv
  • 155
  • 7
  • 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). – Jörg W Mittag Dec 22 '14 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 '14 at 02:39
  • even Donald Knuth's WEB literate programming system was compiled by hand that way – phuclv Dec 23 '14 at 04:43
  • 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 '14 at 22:33
  • 4
    @nnnnnn: I would consider this "bunch of students" an interpreter, not a compiler. – Paŭlo Ebermann Dec 25 '14 at 18:23
  • 5
    @Paŭlo Ebermann To add another human element: "computer" was originally a [job title](http://en.wikipedia.org/wiki/Human_computer). – chux - Reinstate Monica Jan 03 '15 at 06: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.

Basile Starynkevitch
  • 32,434
  • 6
  • 84
  • 125
  • Golang was like that for a while; written in C until it was written in Go. – Henry Malinowski Aug 20 '20 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!! – Gulshan Chaurasia Mar 12 '21 at 08: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.

  • 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. – Solomon Slow Sep 22 '17 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](https://en.wikipedia.org/wiki/ALGOL). – Solomon Slow Sep 22 '17 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 09 '19 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 09 '19 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.

Hartmut Braun
  • 246
  • 1
  • 7
  • 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 '21 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](https://en.m.wikipedia.org/wiki/Small-C) 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 '21 at 19:44
  • PyPy works similarly. The toolchain for the RPython subset it's written in bootstraps from CPython. – ssokolow Sep 30 '21 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.)

ssokolow
  • 161
  • 1
  • 4