Skip to main content
125 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
108 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
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
  • 210k
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
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
57 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

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
  • 519
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
  • 135k
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
37 votes

Why is it necessary to mark classes as not inherited from? Can't an optimizer automatically detect that virtual calls are unnecessary?

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,954
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.4k
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
  • 59.9k
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
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

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
22 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
21 votes
Accepted

"Write an Assembler in C." Why writing a machine code translator for a low level language in a higher level language?

People have written assemblers in machine code. They've also written then in assembly language--often a subset of the language they translate themselves, so they start with a simple "bootstrap" ...
Jerry Coffin's user avatar
  • 44.5k
21 votes
Accepted

How are variables stored in a language compiler or interpreter?

Interpreter An intepreter will work about the way you guessed. In a simple model, it will maintain one dictionary with the variable names as dictionary keys and the variable values as dictionary ...
Ralf Kleberhoff's user avatar
20 votes

How can we avoid showing the literal path in the exception's stack trace?

Couple of pointers. You should never expose stacktrace to users. Thats a security risk. You should also never expose exception messages to users, only for custom exceptions that you know can not ...
Anders's user avatar
  • 661
19 votes
Accepted

Why do compilers typically only generate executables for the platform they are installed on?

what makes it difficult for say the visual C++ compiler on windows to generate a linux binary executable file? Other than an unwillingness to do that on Microsoft's part, absolutely nothing. The ...
Blrfl's user avatar
  • 20.4k
18 votes
Accepted

How are generics implemented in a modern compiler?

How are generics implemented in a modern compiler? I invite you to read the source code of a modern compiler if you wish to know how a modern compiler works. I'd start with the Roslyn project, which ...
Eric Lippert's user avatar
  • 46.3k
18 votes

Can we make general statements about the performance of interpreted code vs compiled code?

You absolutely can say something about the performance of compiled/interpreted technologies. But first, you must define "performance". If you're building a computationally simple embedded system, then ...
jhbh's user avatar
  • 289
17 votes
Accepted

What is the common procedure used when compilers statically type check "complex" expressions?

Recursion is the answer, but you descend into each subtree before handling the operation: int a = 1 + 2 - 3 * 4 - 5 to tree form: (assign (a) (sub (sub (add (1) (2)) (mul (3) (4))) (5)) Inferring ...
Simon Richter's user avatar
17 votes

Detect manual changes to an autogenerated C header

First a disclaimer: I don't think this is a good idea. But here is one way to do it anyway: void check_file_time() { if (strcmp(__TIMESTAMP__, "Sun Feb 16 19:38:35 2020") != 0) { asm(...
jpa's user avatar
  • 1,378
15 votes

How can a compiler be written for a language that allows rewriting code at runtime (such as Lisp macros)?

You are confusing two different concepts in your question. Macros are not about compiling code at runtime. They are the exact opposite: they are about running code at compile time. So, in this case, ...
Jörg W Mittag's user avatar

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