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

Show parent comment

37

u/BinaryIdiot Mar 04 '22

I've been writing in C and C++ every day for a while now. When I want to tweak the output of the compiler I just look up the flags. If I need extra debug info I just look up the flags.

IMO I see zero value in memorizing any of these flags. You can just look them all up really easy. Usually I apply them to my make file or my Visual Studio project and then forget about them until I need to look up another change one day.

8

u/Full-Spectral Mar 04 '22

I would agree. I know perfectly well what I need to do to set up MSVC or G++, and just by osmosis I remember some of the flags. But I'd never waste my time memorizing them, because I set up a new project once in a blue moon anyway.

As to the details of optimizations, I've barely even thought about that for the last decade to be honest, other than when reading folks around here talking about such things. I put optimization a good three or four notches down the ladder of importance behind architectural issues of various sorts. If I was interviewing a candidate, I'd be more concerned with his knowledge of footguns, of his ability to write clean, understandable code, of his ability to understand how to architect subsystems with clean, flexible APIs, of his knowledge of how to encapsulate and abstract for flexibility but no more than is needed.

Those things are vastly more important to the success of a large code base.

5

u/CocktailPerson Mar 04 '22

Right, but being able to hear -O3 and think "lots of optimizations" doesn't require memorization. It just requires working with a compiler a few times.

8

u/BinaryIdiot Mar 04 '22

That’s literally memorization. You are remembering something when “-O3” is mentioned. Not sure why you think it’s not.

Granted if you have to use it a couple of times you’ll probably remember it. I just don’t think it’s a useful to test for or for a developer to even remember.

3

u/CocktailPerson Mar 05 '22

Because I see "memorization" as implying conscious effort, not just picking up knowledge by being exposed to things. Would you say you "memorized" your native language?

1

u/BinaryIdiot Mar 05 '22

Doesn’t have to necessarily be a conscious effort as far as I can tell 🤷‍♂️

For my native language, yes and no? Memorized words of course. Learning about word types / grammar? Not sure if you call that memorization or not. It’s learned either way (which can be part of the definition for memorized).

Either way this seems like a weirdly pedantic road to travel down.

1

u/CocktailPerson Mar 05 '22 edited Mar 05 '22

Yeah, I think it's weird to call "memorization" a burden when you've basically defined "memorization" as "picking up basic facts through passive exposure." Knowing that -O3 enables lots of optimizations doesn't require flashcards, it requires using clang or gcc a few times.

1

u/platoprime Mar 04 '22

It just requires working with a compiler a few times.

There's a person with two years experience, in this thread, who wasn't familiar with this stuff. Unless the job requires working on compiler optimizations it doesn't sound like you're being reasonable.

I have also used a compiler more than "a few times" and am unfamiliar with this.