124
votes
How does garbage collection work in languages which are natively compiled?
Does the compiler store a copy of some garbage collection program and paste it into each executable it generates?
It sounds unelegant and weird, but yes. The compiler has an entire utility library, ...
109
votes
Accepted
Can we make general statements about the performance of interpreted code vs compiled code?
No.
In general, the performance of a language implementation is primarily dependent on the amount of money, resources, manpower, research, engineering, and development spent on it.
And specifically, ...
105
votes
Accepted
How can we be certain that the lower components of computer programming like compilers, assemblers, machine instructions, etc. are flawless?
You can't be certain, but you just assume they are, until you discover they are not. There have been plenty of bugs in compilers and hardware over the years.
The way these are tested, for example a ...
95
votes
Detect manual changes to an autogenerated C header
I think you are approaching this problem from the wrong angle.
Better let the generator place a clear and visible comment at the beginning of the C header file like
// This file is autogenerated, ...
81
votes
Does an interpreter produce machine code?
The terms "interpreter" and "compiler" are much more fuzzy than they used to be. Many years ago it was more common for compilers to produce machine code to be executed later, while interpreters more ...
80
votes
Can we make general statements about the performance of interpreted code vs compiled code?
Generalizations and specific scenarios are literally opposites.
You seem to be contradicting yourself. On the one hand, you want to make a general statement about interpreted vs compiled languages. ...
79
votes
Accepted
Is it bad practice to use a C++ compiler just for function overloading?
I wouldn't go so far as to call it "bad practice" per se, but neither am I convinced it's really the right solution to your problem. If all you want is four separate functions to do your four data ...
67
votes
Accepted
Why does the documentation on some languages say "equivalent to" rather than "is"?
Because the standard writers don't want to actually assert an implementation. They want to define what it does, but not necessarily how it does it. So, for example, if you look at the GNU C++ ...
60
votes
How does garbage collection work in languages which are natively compiled?
Or does the compiler include some minimal garbage collector in the compiled program's code.
That’s an odd way of saying “the compiler links the program with a library that performs garbage collection”...
57
votes
Is it bad practice to use a C++ compiler just for function overloading?
Using only some features of C++ while otherwise treating it as C is not exactly common, but also not exactly unheard of either. In fact, some people even use no features at all of C++, except the ...
56
votes
Accepted
How does garbage collection work in languages which are natively compiled?
Garbage collection in a compiled language works the same way as in an interpreted language. Languages like Go use tracing garbage collectors even though their code is usually compiled to machine code ...
54
votes
Do compilers optimise in concurrency?
Asuming expensive_calc_one and expensive_calc_two are pure functions
Unfortunately, determining whether a function is pure is equivalent to solving the Halting Problem in the general case. So, you ...
46
votes
How can we be certain that the lower components of computer programming like compilers, assemblers, machine instructions, etc. are flawless?
In layman's terms:
You cannot.
Compilers and interpreters are unit-tested as any other (professional) software.
A sucessful test doesn't mean a program is bug-free, it only means no bugs were ...
45
votes
What is the common procedure used when compilers statically type check "complex" expressions?
What is the usually method used when a compiler is type checking expressions with many operators and operands.
Read wikipages on type system and type inference and on Hindley-Milner type system, ...
41
votes
Detect manual changes to an autogenerated C header
Don't commit the generated C header file at all. In fact, delete the current file (thanks @user1936), change the script to call the header file .g.h (thanks @davidbak),
and add it to .gitignore, so ...
38
votes
Does an interpreter produce machine code?
The summary I give below is based on "Compilers, Principles, Techniques, & Tools", Aho, Lam, Sethi, Ullman, (Pearson International Edition, 2007), pages 1, 2, with the addition of some ideas of my ...
37
votes
Can we make general statements about the performance of interpreted code vs compiled code?
As a rule of thumb, an interpreted program is about 2x–10x slower than writing the program in the interpreter's host language, with interpreters for more dynamic languages being slower. This is ...
37
votes
Accepted
How do compilers work in a language that doesn't allow recursion?
Recursion can only be programmed either by having a call to function A within the definition of A itself (direct), or by having function A call function B, and function B call function A (indirect). ...
35
votes
C# and C++ Inheritance and Performance - Shouldn't Compilers Handle this Issue?
Don't we need to take a step back here?
Under the hood, it generally all boils down to simply functions being called the with the this pointer as first arg.
It's good to question things from first ...
34
votes
Accepted
In which process does syntax error occur? (tokenizing or parsing)
A tokenizer is just a parser optimization. It's perfectly possible to implement a parser without a tokenizer.
A tokenizer (or lexer, or scanner) chops the input into a list of tokens. Some parts of ...
29
votes
Accepted
What exactly is a compile target?
Compilers are, in essence, translators that take input in one language and produce output in another. For example, Eiffel Software's compiler takes Eiffel-language input and produces C. GCC for ...
27
votes
How do compilers work in a language that doesn't allow recursion?
To support recursion, a language needs to support function calls and a call stack. When a language doesn't allow recursion, it's typically because the language lacks one of these features. I'm not ...
25
votes
Accepted
Is it possible to create a "bootstrapped" interpreter independent of the original interpreter?
The short answer is: you are right in your suspicion, you always need either another interpreter written in X or a compiler from Y to some other language for which you have an interpreter already. ...
24
votes
Does an interpreter produce machine code?
A compiler would create machine language
No. A compiler is simply a program which takes as its input a program written in language A and produces as its output a semantically equivalent program in ...
24
votes
How can we be certain that the lower components of computer programming like compilers, assemblers, machine instructions, etc. are flawless?
It's turtles all the way down.
Nothing is certain. You have no choice but to settle on confidence ratings.
You can think of it as a stack:
Math > Physics > Hardware > Firmware > Operating System > ...
23
votes
Why isn't the overloading with return types allowed? (at least in usually used languages)
It complicates type checking.
When you only permit overloading based on argument types, and only permit deducing variable types from their initialisers, all of your type information flows in one ...
23
votes
Accepted
What semantic features of Python (and other dynamic languages) contribute to its slowness?
What semantic features of Python (and other dynamic languages) contribute to its slowness?
None.
Performance of language implementations is a function of money, resources, and PhD theses, not ...
23
votes
"Write an Assembler in C." Why writing a machine code translator for a low level language in a higher level language?
You are seeing connections that don't exist.
"Write an assembler" is a programming task just like any other programming task. You use the tools to handle that task that are best for that task. There ...
23
votes
How does garbage collection work in languages which are natively compiled?
How would this work with compiled languages though?
Your wording is wrong. A programming language is a specification written in some technical report (for a good example, see R5RS). Actually you are ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
compiler × 494programming-languages × 64
c × 61
c++ × 60
interpreters × 42
parsing × 40
optimization × 35
java × 26
language-design × 26
assembly × 26
c# × 23
python × 18
javascript × 17
performance × 16
grammar × 14
computer-science × 13
jit × 13
language-agnostic × 12
machine-code × 12
design × 11
compilation × 11
lexer × 11
llvm × 11
architecture × 10
.net × 10