r/cpp • • Mar 04 '22

Is it unreasonable to ask basic compiler questions in a C++ developer interview?

I interviewed a guy today who listed C++ on his resume, so I assumed it would be safe to ask a bit about compilers. My team works on hardware simulation, so he's not going to be expected to write a compiler himself, but he'll obviously be required to use one and to write code that the compiler can optimize well. My question was "what sorts of optimizations does a compiler perform?" Even when I rephrased it in terms of -O0 vs. -O3, the best he could do was talk about "removing comments" and the preprocessor. I started out thinking a guy with a masters in CS might be able to talk about register allocation, loop unrolling, instruction reordering, peephole optimizations, that sort of thing, but by the time I rephrased the question for the third time, I would have been happy to hear the word "parser."

There were other reasons I recommended no-hire as well, but I felt kind of bad for asking him a compiler question when he didn't have that specifically on his resume. At the same time, I feel like basic knowledge of what a compiler does is important when working professionally in a compiled language.

Was it an unreasonable question given his resume? If you work with C++ professionally, would you be caught off guard by such a question?

335 Upvotes

335 comments sorted by

View all comments

37

u/Wetmelon Mar 04 '22

I don't think this is unreasonable at all. Writing code for an optimizing compiler is an important topic in C++. Even just understanding why an -O3 build might be harder to debug than -Og is a pretty basic requirement.

5

u/CocktailPerson Mar 04 '22

Yeah, that was my thought process too. If you don't know how what the compiler's doing, how do you expect to choose what code to feed it so it can do its job as well as possible?

8

u/JNighthawk gamedev Mar 04 '22

If you don't know how what the compiler's doing, how do you expect to choose what code to feed it so it can do its job as well as possible?

We all stand on the shoulders of giants. There's always going to be things you don't know, including things that you are depending on. That's society's collective advancement of knowledge. You can walk that knowledge tree down forever, including to stuff that humanity just doesn't know yet: Do you know what machine code that assembly compiles into? Do you know what logic gates that machine code uses? Do you know how the electricity works in that logic gate? Do you know the quantum physics behind that electricity? And probably many more layers I'm leaving out.

It really just depends on how necessary you think that knowledge is to the job, not really on whether you think a programmer should have it in general. There's infinite knowledge out there, and we don't have time to learn it all.

1

u/CocktailPerson Mar 04 '22

The more layers you peel back, the smaller the benefit; not all the layers are equivalent. Knowledge of common, simple compiler optimizations is a lot more useful for the working C++ programmer than quantum physics is. Even if the knowledge isn't necessary for the job, if choosing between otherwise equivalent, qualified candidates, I'm going with the one who knows a bit about how a compiler works, because it's knowledge a programmer should have.

→ More replies (12)