4 ms·
Most other languages are implemented in C, so there's an obvious reason that it has some advantages over everything else. That the OS typically depends on the
by tyingq 6y ago
Most other languages are implemented in C, so there's an obvious reason that it has some advantages over everything else. That the OS typically depends on the C ABI makes it mandatory. You can find warts, but as of now, there isn't a broadly proven alternative for some use cases.
- jcranmer 6y ago> Most other languages are implemented in C I'm not entirely sure what you mean here, but this is true for neither of the interpretations I have. Most compilers are not written in the C language (indeed, even the major C compilers are all written in C++ now!). Alternatively, most languages compile down into a bytecode language, or into native assembly, without converting into anything that is or looks like C in the process. Indeed, for languages targeting native assembly, C is an unwelcome intermediate step precisely because its semantics can be too constraining.
- tyingq 6y ago"I'm not entirely sure what you mean here" I mean that most of the popular languages I'm familiar with are written in C.
- Thiez 6y agoGCC is written in C++ these days, and LLVM has always been C++. Perhaps some languages are written in C, but C itself hasn't been for some time, if you look at the most popular compilers.
- jcranmer 6y agoThat doesn't clear up any of my confusion, although that may well be because your experience is mostly with managed languages where the distinction between compiler and runtime is less obvious. Even looking at major languages [1], what do we have: * Self-hosting languages: C#, Go, Haskell, Java, most LISP implementations, OCaml, Pascal, Rust, Swift * C++ implementation: C/C++/Objective-C compilers, Fortran compilers (using the same toolchains as the former), JavaScript, probably Visual BASIC (although that may be C# instead) * C implementation: Perl, PHP, Prolog, Python, R, Ruby, Shell (although note that many of these languages have their libraries largely written in their own language). * Not sure: ALGOL, APL, Cobol, Erlang, Forth, Kotlin, SQL, Simula, Smalltalk. Although I suspect that many of these are self-hosted. 7 of 32 is a far cry from "most languages". [1] Using the list of programming languages in Wikipedia's category box at the bottom here.
- deleted 6y ago[deleted]
- dnautics 6y agoerlang is written in c. somewhat controversially, the new JIT has C++ in it.
- int_19h 6y ago"Self-hosting" can be a bit tricky to define for Forth. A typical implementation would start with a few words defined manually in assembly, and build the rest up from there. That aside, you need to account for multiple implementations. E.g. for Python, CPython is written in C, but PyPy is self-hosted (kinda; it's complicated: https://doc.pypy.org/en/latest/architecture.html#layers https://doc.pypy.org/en/latest/architecture.html#layers).
- steveklabnik 6y ago> Most other languages are implemented in C, Fun fact: even major C implementations are mostly in C++ these days. Ruby, Python...PHP. What else?
- hmry 6y agoPerl too. But yes, it's certainly not "most languages". It's "most interpreted languages" at best, but even then C++ is probably about tied with C. And for compilers, using the language itself is much more popular, often targeting LLVM which is written in C++.
- tyingq 6y agoC++ with lots of extern "C", I imagine. Two examples: https://github.com/Perl/perl5/search?q=extern https://github.com/Perl/perl5/search?q=extern https://github.com/php/php-src/search?q=extern https://github.com/php/php-src/search?q=extern
- steveklabnik 6y agoAh so, "implemented in C" usually does not mean "uses the C ABI even though it's implemented in another language." If that's what you meant, then I very seriously misunderstood you.