Compiled vs interpreted is not a property of the compiler.
I assume you meant "language." You're of course correct, but if ever there were a language that deserved to be called "compiled," C is it. It truly was designed to be compiled, and who in their right mind would bother interpreting it?
And before you ask, no, people who debug C are rarely in their right minds. :)
That's really an interpreter (as opposed to using a bytecode vm or some such)? How does it deal with memory allocation, alignment etc? And (I don't have a proper dev setup on hand) -- the obvious question -- can it run itself, in itself in itself? (And itself in tcc in itself?) ;-)
It's a real interpreter. It runs directly from the source code - it doesn't even store a parse tree or bytecode. Memory allocation and alignment is done in the standard C ways. It's designed as a scripting variant of C so it doesn't implement 100% of the C standard (eg. bitfields), so no it's not self-hosting.
Fascinating, I'll have to look at it more closely when I've got a usable command line available. I would not have thought it was feasible for a useful subset of C -- but then I tend to forget that it is a rather simple language at heart (eg: after running the pre-prosessor).
if ever there were a language that deserved to be called "compiled," C is it.
I was only clarifying the other guy's comment, but I do appreciate the desire to be careful with the meaning of technical terms, lest they get diluted and become less useful.
It truly was designed to be compiled, and who in their right mind would bother interpreting it?
Lots of people can (and do!) interpret C, or some subset, superset, or abstraction of C, for a great many purposes. Consider debuggers, IDEs, formal verification systems, build systems, security tools, etc.
Physicists at CERN :), their analysis framework ROOT is bundled with a C/C++ interpreter. I had only occasion to use it once, but it was a fairly pleasant experience.
I'm not sure - what qualities of a language make it designed for compilation?
I'd say no high level abstractions, no need for a runtime keeping track of what you're doing (garbage collector, bound checks etc...)
The standard also describes a bunch of undefined/undetermined behaviours to let the compiler generate machine code as efficient as possible and without the need for a runtime (or as small a runtime as possible).
None of those things forbid an interpreted implementation but it makes less sense to leave those gotchas into the language if you don't have to talk to the CPU directly, it makes more sense to let the interpreter take care of the architecture-dependent details.
what qualities of a language make it designed for compilation?
That a language that compiled to good machine code was one of the main goals of the people who designed it. I was making a historical statement, not a qualitative one.
People tend to compile their C code. It's probably more accurate to speak of tendencies in how it's implemented and used then to assign attributes to the language.
And the reality is that languages are not compiled or interpreted, but there are implementation of language compilers or interpreters. The C language isn't "compiled", but there are some implementations of C compilers, and some implementations of C interpreters.
Another good example, is an old language, "BASIC", which a lot of people used the interpreted version, but, as early as 1987, I used a BASIC compiler which provided as much as a 100x increase in performance over the common interpreter that came with my system.
Python is another great example - lots of Python interpreters out there, but Cython lets you compile your python code to machine code.
A disclaimer: this post focuses on how things typically work on modern consumer operating systems (especially Linux and Windows), rather than trying to cover all possible obscure systems. C doesn't have to work like this. It just normally does in practice.
Python: Interpreted language, right? Then what are all those .pyc files doing? You can say it's compiled into an interpreted form, but then JVM bytecode comes along, which is interpreted right up until you find an implementation that JITs. Or is it only compiled if you save the compiled form to disk, like you do with gcj?
Scheme: An interpreted language in Guile, a compiled language in Stalin?
Comments
Eh?
Um...that's true?
Compiled vs interpreted is not a property of the language. It's a (vague) property of a particular implementation.
I assume you meant "language." You're of course correct, but if ever there were a language that deserved to be called "compiled," C is it. It truly was designed to be compiled, and who in their right mind would bother interpreting it?
And before you ask, no, people who debug C are rarely in their right minds. :)
Um... me?
https://code.google.com/p/picoc/
That's really an interpreter (as opposed to using a bytecode vm or some such)? How does it deal with memory allocation, alignment etc? And (I don't have a proper dev setup on hand) -- the obvious question -- can it run itself, in itself in itself? (And itself in tcc in itself?) ;-)
It's a real interpreter. It runs directly from the source code - it doesn't even store a parse tree or bytecode. Memory allocation and alignment is done in the standard C ways. It's designed as a scripting variant of C so it doesn't implement 100% of the C standard (eg. bitfields), so no it's not self-hosting.
Fascinating, I'll have to look at it more closely when I've got a usable command line available. I would not have thought it was feasible for a useful subset of C -- but then I tend to forget that it is a rather simple language at heart (eg: after running the pre-prosessor).
Do you support GOTOs?
#ifdefs?
aligment #pragmas?
#includes?
extern?
If you don't--which is integral to how C works--you've created a cool C-like language, but not C.
C is quite nearly just a high-level assembler with syntax sugar.
Yes, of course, I've fixed my post. Thanks.
I was only clarifying the other guy's comment, but I do appreciate the desire to be careful with the meaning of technical terms, lest they get diluted and become less useful.
Lots of people can (and do!) interpret C, or some subset, superset, or abstraction of C, for a great many purposes. Consider debuggers, IDEs, formal verification systems, build systems, security tools, etc.
Physicists at CERN :), their analysis framework ROOT is bundled with a C/C++ interpreter. I had only occasion to use it once, but it was a fairly pleasant experience.
https://www.softintegration.com/
I'm not sure - what qualities of a language make it designed for compilation?
I'd say no high level abstractions, no need for a runtime keeping track of what you're doing (garbage collector, bound checks etc...)
The standard also describes a bunch of undefined/undetermined behaviours to let the compiler generate machine code as efficient as possible and without the need for a runtime (or as small a runtime as possible).
None of those things forbid an interpreted implementation but it makes less sense to leave those gotchas into the language if you don't have to talk to the CPU directly, it makes more sense to let the interpreter take care of the architecture-dependent details.
But pedants are going to be pedants.
That a language that compiled to good machine code was one of the main goals of the people who designed it. I was making a historical statement, not a qualitative one.
In some cases interpreting C can be faster and more convenient: http://www.chrisseaton.com/rubytruffle/cext/.
Meanwhile, in reality, C is a compiled language.
People tend to compile their C code. It's probably more accurate to speak of tendencies in how it's implemented and used then to assign attributes to the language.
No, it's accurate to describe reality rather than hypotheticals.
And the reality is that languages are not compiled or interpreted, but there are implementation of language compilers or interpreters. The C language isn't "compiled", but there are some implementations of C compilers, and some implementations of C interpreters.
Another good example, is an old language, "BASIC", which a lot of people used the interpreted version, but, as early as 1987, I used a BASIC compiler which provided as much as a 100x increase in performance over the common interpreter that came with my system.
Python is another great example - lots of Python interpreters out there, but Cython lets you compile your python code to machine code.
So, what you're saying is that C is (usually) compiled?
FWIW, from the post:
And then there's the rest of the world:
Python: Interpreted language, right? Then what are all those .pyc files doing? You can say it's compiled into an interpreted form, but then JVM bytecode comes along, which is interpreted right up until you find an implementation that JITs. Or is it only compiled if you save the compiled form to disk, like you do with gcj?
Scheme: An interpreted language in Guile, a compiled language in Stalin?