In a very similar manner, the main point of high level language to C translators is immediate portability, as there's a C compiler for almost every platform and an abundance of C libraries. Vala, for example, was designed to:
- be a compiler for the GObject,
- build native executables (through the machine's C compiler),
- automate reference counting, and
- still be accessible to GNOME C programmers
GNOME is a traditionally C oriented project and GObject specifically is written in C, Vala wouldn't probably find much love amongst GNOME developers if it compiled to machine code, regardless of it's friendlier nature (and syntax). Not everyone seemed to like the syntax, to the point that another language, Genie, was build to improve upon it.
For a C++ example, Facebook developed HipHop, a PHP to C++ translator. They were trying to solve a very specific issue, CPU usage, without having to replace all their PHP code and re-train their engineers (or worst, replace them). This is a far more specific example, as Facebook scalability issues are, well, unique, and again having access to the intermediate C++ code can be useful, as PHP extensions are written in C and C++.
But generally speaking, it wouldn't be such a good idea to build a language that translates to C, or any other language, if you didn't have any use of the resulting code. There are so many languages out there, if you can't cope with C, just pick an other. Coincidentally the first C++ compiler written by Bjarne Stroustrup, CFront, was a C with Classes to C translator, but that was mainly because as a new language, it was impossible to bootstrap C with Classes.
I'm going to cover a few points Yannis Rizos didn't in his otherwise great answer.
Yes, many languages exist. C is a common target for compiler back-ends as it's incredibly portable and heavily optimized, although with LLVM there's not much point to it.
A few implementations I know that do this are:
- C++ (At least in the early days)
- GHC Haskell (Although the main code generator is C--)
- Gambit/Chicken/Bigloo Scheme
- ECL (Common Lisp)
- Vala & Genie
as fast as original C programs
No, just because it uses C as an intermediate language doesn't mean you will reach its speed. The reason C is fast is because of the method of writing the code which is obviously different for other languages. It's just a portable assembly, nothing special.
Rock is an ooc compiler that generates C99 source. The ooc-lang is a programming language with objects, first-class functions, and pink unicorns. The ooc is a dynamic-language and walks so far away. It generates fatter and slower c codes. u need modified more to suite your requirement. But it is a good start point.
OCaml can compile to bytecode, to native code, can be interpreted directly, or can compile to C.
- Bjarne Stroustrop's original C++ compiler, "cfront", compiled C++ to C, which it would then optionally run the C compiler against to produce object code. C++ is about as "non-theoretical" as you can get :-)
- The Unix "yacc" and GNU "Bison" compiler-compilers translate their input languages to C. Many, many sophisticated systems have been written with them.