Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

std::swap<>? CMPXCHG? LDREX/STREX?

The XOR trick is cute but you shouldn't use it on anything larger or more modern than a Cortex-M0. Just put it through a temporary variable and let register renaming deal with it.

(Perhaps a more interesting question would be a multi-threaded examination of swapping two numbers...)



It's interesting because this is a real answer that will get you hired. It demonstrates knowledge of: the "correct" way to do it, basic asm awareness, programmer culture, and computer architecture. This probably checks off like 6 boxes for most technical interviewers in one answer.

Finally it implies it could have asked a better interview question ;)


Thankyou. I try to strike a balance with these things - showing off is mandatory in interviews, but needs to be done politely. You don't want to go full "Hexing the Technical Interview": https://aphyr.com/posts/341-hexing-the-technical-interview


This is basically the perfect answer to that question.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: