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, ...
Kilian Foth's user avatar
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, ...
Jörg W Mittag's user avatar
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 ...
whatsisname's user avatar
  • 27.7k
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, ...
Doc Brown's user avatar
  • 203k
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 ...
Robert Harvey's user avatar
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. ...
loneboat's user avatar
  • 971
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 ...
Philip Kendall's user avatar
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++ ...
Gort the Robot's user avatar
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”...
Konrad Rudolph's user avatar
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 ...
Jörg W Mittag's user avatar
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 ...
avdgrinten's user avatar
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 ...
Jörg W Mittag's user avatar
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 ...
Tulains Córdova's user avatar
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, ...
Basile Starynkevitch's user avatar
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 ...
Jonathan's user avatar
  • 501
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 ...
Giorgio's user avatar
  • 19.6k
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 ...
amon's user avatar
  • 133k
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). ...
Kilian Foth's user avatar
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 ...
Alexander's user avatar
  • 4,410
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 ...
amon's user avatar
  • 133k
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 ...
Blrfl's user avatar
  • 20.3k
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 ...
JacquesB's user avatar
  • 57.7k
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. ...
Jörg W Mittag's user avatar
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 ...
Jörg W Mittag's user avatar
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 > ...
voutasaurus's user avatar
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 ...
Jon Purdy's user avatar
  • 20.5k
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 ...
Jörg W Mittag's user avatar
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 ...
gnasher729's user avatar
  • 43.4k
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 ...
Basile Starynkevitch's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible